Changeset 101
- Timestamp:
- Sep 28, 2022, 9:38:10 PM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UEngine.pas
r100 r101 33 33 ShapeDistance: array[TStationShape] of Integer; 34 34 OverloadDuration: TDateTime; 35 IsTerminal: Boolean; 36 function GetMaxPassengers: Integer; 35 37 function IsBestStationForShape(Shape: TStationShape; Check, Current: TLineStation): Boolean; 36 38 constructor Create; … … 185 187 IconSize: Integer; 186 188 LineColors: array of TColor; 189 CarriageCountVisible: Boolean; 190 TerminalCountVisible: Boolean; 187 191 function GetServedDaysCount: Integer; 188 192 procedure ResizeView; … … 207 211 procedure DrawStations(Canvas: TCanvas); 208 212 procedure DrawGameControls(Canvas: TCanvas; CanvasSize: TPoint); 213 procedure DrawGrabbed(Canvas: TCanvas; CanvasSize: TPoint); 209 214 procedure ComputeShapeDistance; 210 215 procedure ComputeShapeDistanceStation(Station: TMapStation; … … 239 244 procedure EvaluateImprovement(Improvement: TMetroImprovement); 240 245 public 246 AvailableTerminals: Integer; 241 247 Week: Integer; 242 248 Colors: TColors; … … 254 260 SelectedTrain: TMetroTrain; 255 261 SelectedCarriage: TMetroCarriage; 262 SelectedTerminal: Boolean; 256 263 TrackStationDown: TTrackPoint; 257 264 TrackStationUp: TTrackPoint; … … 314 321 StationMaxDistance = 300; 315 322 MaxWaitingPassengers = 10; 323 MaxWaitingPassengersTerminal = 16; 316 324 MaxPassengersOveloadTime = 2; 317 325 MetroLineThickness = 13; … … 968 976 begin 969 977 Lines.Sort(TComparer<TMetroLine>.Construct(MapStationCompareLine)); 978 end; 979 980 function TMapStation.GetMaxPassengers: Integer; 981 begin 982 if IsTerminal then Result := MaxWaitingPassengersTerminal 983 else Result := MaxWaitingPassengers; 970 984 end; 971 985 … … 1997 2011 miCarriage: Carriages.AddNew; 1998 2012 //miTunnel: Tunnels.AddNew; 1999 //miTerminal: Terminals.AddNew;2013 miTerminal: Inc(AvailableTerminals); 2000 2014 end; 2001 2015 end; … … 2555 2569 PassengerPos: TPoint; 2556 2570 Direction: Integer; 2571 UsedStationSize: Integer; 2557 2572 begin 2558 2573 Canvas.Pen.Width := 5; … … 2560 2575 with MapStation do begin 2561 2576 Canvas.Pen.Style := psSolid; 2577 if IsTerminal then UsedStationSize := Round(StationSize * 1.5) 2578 else UsedStationSize := StationSize; 2579 2562 2580 if Assigned(SelectedLine) and (Lines.IndexOf(SelectedLine) <> -1) then begin 2563 2581 Canvas.Brush.Style := bsClear; 2564 2582 Canvas.Pen.Color := SelectedLine.Color; 2565 DrawShape(Canvas, Position, Shape, StationSize + Canvas.Pen.Width + 4, 0);2583 DrawShape(Canvas, Position, Shape, UsedStationSize + Canvas.Pen.Width + 4, 0); 2566 2584 end; 2567 2585 … … 2569 2587 Canvas.Brush.Style := bsSolid; 2570 2588 Canvas.Pen.Color := Colors.Text; 2571 DrawShape(Canvas, Position, Shape, StationSize, 0);2589 DrawShape(Canvas, Position, Shape, UsedStationSize, 0); 2572 2590 2573 2591 // Draw passengers … … 2658 2676 2659 2677 // Draw unused carriages 2660 Text := IntToStr(Carriages.GetUnusedCount); 2661 ImageCarriage.Bounds := Bounds(X - IconSize, Y - IconSize div 2, 2662 IconSize, IconSize); 2663 ImageCarriage.Canvas := Canvas; 2664 ImageCarriage.Paint; 2665 X := X - IconSize - SeparatorSize div 3; 2666 2667 Canvas.Brush.Style := bsClear; 2668 Canvas.Font.Size := 14; 2669 Canvas.Font.Color := Colors.Text; 2670 Canvas.TextOut(X - Canvas.TextWidth(Text), 2671 Y - Canvas.TextHeight(Text) div 2, Text); 2678 if Carriages.GetUnusedCount > 0 then CarriageCountVisible := True; 2679 if CarriageCountVisible then begin 2680 Text := IntToStr(Carriages.GetUnusedCount); 2681 ImageCarriage.Bounds := Bounds(X - IconSize, Y - IconSize div 2, 2682 IconSize, IconSize); 2683 ImageCarriage.Canvas := Canvas; 2684 ImageCarriage.Paint; 2685 X := X - IconSize - SeparatorSize div 3; 2686 2687 Canvas.Brush.Style := bsClear; 2688 Canvas.Font.Size := 14; 2689 Canvas.Font.Color := Colors.Text; 2690 Canvas.TextOut(X - Canvas.TextWidth(Text), 2691 Y - Canvas.TextHeight(Text) div 2, Text); 2692 X := X - Canvas.TextWidth(Text) - SeparatorSize; 2693 end; 2694 2695 // Draw unused terminals 2696 if AvailableTerminals > 0 then TerminalCountVisible := True; 2697 if TerminalCountVisible then begin 2698 Text := IntToStr(AvailableTerminals); 2699 ImageTerminal.Bounds := Bounds(X - IconSize, Y - IconSize div 2, 2700 IconSize, IconSize); 2701 ImageTerminal.Canvas := Canvas; 2702 ImageTerminal.Paint; 2703 X := X - IconSize - SeparatorSize div 3; 2704 2705 Canvas.Brush.Style := bsClear; 2706 Canvas.Font.Size := 14; 2707 Canvas.Font.Color := Colors.Text; 2708 Canvas.TextOut(X - Canvas.TextWidth(Text), 2709 Y - Canvas.TextHeight(Text) div 2, Text); 2710 end; 2672 2711 2673 2712 // Passenger count … … 2720 2759 Y - Round(1.5 * IconSize) - Canvas.TextHeight(Text) div 2, Text); 2721 2760 end; 2722 2761 end; 2762 2763 procedure TEngine.DrawGrabbed(Canvas: TCanvas; CanvasSize: TPoint); 2764 var 2765 Pos: TPoint; 2766 Angle: Double; 2767 begin 2723 2768 // Show train grabbed by mouse 2724 2769 if Assigned(SelectedTrain) then begin … … 2751 2796 RotatePoint(Pos, Point(Pos.X - TrainSize div 2, Pos.Y + TrainSize div 3), Angle) 2752 2797 ]); 2798 end; 2799 2800 // Show grabbed terminal by mouse 2801 if SelectedTerminal then begin 2802 Canvas.Brush.Color := Colors.Text; //SelectedTrain.Line.Color; 2803 Canvas.Brush.Style := bsSolid; 2804 Canvas.Pen.Style := psClear; 2805 Pos := LastMousePos; 2806 Angle := 0; 2807 2808 Canvas.Ellipse(Pos.X - TrainSize div 2, Pos.Y - TrainSize div 2, 2809 Pos.X + TrainSize div 2, Pos.Y + TrainSize div 2); 2753 2810 end; 2754 2811 end; … … 2807 2864 for MapStation in Stations do 2808 2865 with MapStation do begin 2809 if Passengers.Count > MaxWaitingPassengers then begin2866 if Passengers.Count > GetMaxPassengers then begin 2810 2867 OverloadDuration := OverloadDuration + (FTime - FLastTime); 2811 2868 if OverloadDuration > MaxPassengersOveloadTime then … … 2813 2870 if OverloadDuration < MaxPassengersOveloadTime then Redraw; 2814 2871 end; 2815 if Passengers.Count <= MaxWaitingPassengers then begin2872 if Passengers.Count <= GetMaxPassengers then begin 2816 2873 if OverloadDuration > 0 then Redraw; 2817 2874 OverloadDuration := OverloadDuration - (FTime - FLastTime); … … 2855 2912 end; 2856 2913 2857 if Assigned(SelectedTrain) or Assigned(SelectedCarriage) then Redraw; 2914 if Assigned(SelectedTrain) or Assigned(SelectedCarriage) or 2915 SelectedTerminal then Redraw; 2858 2916 2859 2917 LastMousePos := Position; … … 2908 2966 FocusedTrack: TTrackLink; 2909 2967 FocusedTrain: TMetroTrain; 2968 FocusedStation: TMapStation; 2910 2969 begin 2911 2970 if Button = mbLeft then begin … … 2973 3032 end; 2974 3033 3034 if SelectedTerminal then begin 3035 FocusedStation := GetStationOnPos(View.PointDestToSrc(Position)); 3036 if Assigned(FocusedStation) and not FocusedStation.IsTerminal then begin 3037 FocusedStation.IsTerminal := True; 3038 Dec(AvailableTerminals); 3039 Redraw; 3040 end; 3041 SelectedTerminal := False; 3042 end; 3043 2975 3044 // Line color selection 2976 3045 for I := 0 to Lines.Count - 1 do … … 3036 3105 3037 3106 // Select unused carriage 3038 if (Distance(Position, ImageCarriage.Bounds.CenterPoint) < 30) and3107 if CarriageCountVisible and (Distance(Position, ImageCarriage.Bounds.CenterPoint) < 30) and 3039 3108 (Carriages.GetUnusedCount > 0) then begin 3040 3109 SelectedCarriage := Carriages.GetUnused; 3110 Exit; 3111 end; 3112 3113 // Select unused carriage 3114 if TerminalCountVisible and (Distance(Position, ImageTerminal.Bounds.CenterPoint) < 30) and 3115 (AvailableTerminals > 0) then begin 3116 SelectedTerminal := True; 3041 3117 Exit; 3042 3118 end; … … 3094 3170 KeyF6 = 117; 3095 3171 KeyF7 = 118; 3172 KeyF8 = 119; 3096 3173 KeyT = 84; 3097 3174 KeyC = 67; … … 3153 3230 State := gsSuccess; 3154 3231 Redraw; 3232 end else 3233 if Key = KeyF8 then begin 3234 Inc(AvailableTerminals); 3235 Redraw; 3155 3236 end; 3156 3237 end; … … 3166 3247 procedure TEngine.Clear; 3167 3248 begin 3249 CarriageCountVisible := False; 3250 TerminalCountVisible := False; 3251 AvailableTerminals := 0; 3168 3252 ServedPassengerCount := 0; 3169 3253 Week := 1; … … 3188 3272 InitialLineCount := City.InitialLineCount; 3189 3273 end else begin 3190 LineColors := [clBlue, clRed, clDarkYellow, clGreen, 3191 clPurple, clGray,clOrange, clBrown, clCyan];3274 LineColors := [clBlue, clRed, clDarkYellow, clGreen, clPurple, clGray, 3275 clOrange, clBrown, clCyan]; 3192 3276 InitialLineCount := 3; 3193 3277 end; 3194 AvailableImprovements := [miCarriage, miLine ];3278 AvailableImprovements := [miCarriage, miLine, miTerminal]; 3195 3279 ShapeCount := 3; 3196 3280 … … 3380 3464 if State in [gsRunning, gsPaused] then begin 3381 3465 DrawGameControls(Canvas, CanvasSize); 3466 DrawGrabbed(Canvas, CanvasSize); 3382 3467 end; 3383 3468
Note:
See TracChangeset
for help on using the changeset viewer.