- Timestamp:
- Mar 26, 2015, 10:53:11 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UEngine.pas
r10 r11 183 183 ImageLocomotiveName = 'Images/Locomotive.png'; 184 184 TrainPassengerCount = 6; 185 StationMinDistance = 50; 185 StationMinDistance = 100; 186 StationMaxDistance = 300; 186 187 MaxWaitingPassengers = 10; 187 188 … … 236 237 I: Integer; 237 238 Pass: Integer; 239 Angle: Double; 240 L: Integer; 241 const 242 Step = 20; 238 243 begin 239 244 Result := TMetroStation.Create; 240 245 Result.Engine := Engine; 246 Angle := Random * 2 * Pi; 241 247 // Ensure minimum distance between stations 242 248 Pass := 0; 249 L := Step; 243 250 repeat 244 Result.Position := Point(Trunc(Engine.Map.Size.X * 0.1 + Random(Trunc(Engine.Map.Size.X * 0.8))),245 Trunc(Engine.Map.Size.Y * 0.1 + Random(Trunc(Engine.Map.Size.Y * 0.8))));251 Result.Position := Point(Trunc(Engine.Map.Size.X / 2 + Cos(Angle) * L), 252 Trunc(Engine.Map.Size.Y / 2 + Sin(Angle) * L)); 246 253 MinD := High(Integer); 247 254 for I := 0 to Engine.Stations.Count - 1 do begin … … 250 257 end; 251 258 Inc(Pass); 252 until (MinD > StationMinDistance) or (Pass > 100) or (Engine.Stations.Count = 0); 259 L := L + StationMinDistance div 2; 260 until (MinD > StationMinDistance) or 261 (Pass > 1000) or (Engine.Stations.Count = 0); 253 262 Result.Shape := TStationShape(Random(Integer(Engine.ShapeCount))); 254 263 Add(Result); … … 756 765 if (Now - StationStopTime) > OneSecond then begin 757 766 CurrentStationIndex := TargetStationIndex; 758 CurrentStation := TargetStation; 767 if CurrentStationIndex >= Line.Stations.Count then 768 CurrentStationIndex := Line.Stations.Count - 1; 769 CurrentStation := nil; 770 if Assigned(Line) then 771 if (CurrentStationIndex >= 0) and (CurrentStationIndex < Line.Stations.Count) then 772 CurrentStation := TMetroStation(Line.Stations[CurrentStationIndex]); 759 773 760 774 // Choose next target station … … 779 793 780 794 // Unload passengers in target station 795 if Assigned(CurrentStation) and (CurrentStationIndex < Line.Stations.Count) then 781 796 for P := Passengers.Count - 1 downto 0 do begin 782 797 if TMetroPassenger(Passengers[P]).Shape = CurrentStation.Shape then begin … … 788 803 end; 789 804 // Unload passengers to change line 805 if Assigned(CurrentStation) and (CurrentStationIndex < Line.Stations.Count) then 790 806 for P := Passengers.Count - 1 downto 0 do begin 791 if not CurrentStation.GetBestStationForShape(TMetroPassenger(Passengers[P]).Shape, TargetStation, CurrentStationIndex) then begin 807 if not CurrentStation.GetBestStationForShape(TMetroPassenger(Passengers[P]).Shape, 808 TargetStation, CurrentStationIndex) then begin 792 809 Passenger := TMetroPassenger(Passengers[P]); 793 810 Passengers.Delete(P);
Note:
See TracChangeset
for help on using the changeset viewer.