public void SetupTravelPass(TravelPass travelPass)
    {
        LoadDataMachinist();
        LoadDataTrainRoute();
        LoadDataStation();
        // Debug.Log("Travel Pass Machinist Id: " + travelPass.MachinistId);

        travelPassForm.SetActive(true);
        idIF.text = travelPass.Id;

        //Find Machinist
        Machinist machinist = new Machinist();

        for (int i = 0; i < machinists.Count; i++)
        {
            if (machinists[i].Id == travelPass.MachinistId)
            {
                machinist = machinists[i];
            }
        }

        //Find Train Route
        TrainRoute trainRoute = new TrainRoute();

        for (int i = 0; i < trainRoutes.Count; i++)
        {
            if (trainRoutes[i].Id == travelPass.TrainRouteId)
            {
                trainRoute = trainRoutes[i];
            }
        }
        machinistIF.text  = machinist.Name;
        trainRouteIF.text = trainRoute.Name;
    }
Esempio n. 2
0
    private void LoadRoutes()
    {
        if (!File.Exists(".\\trains.fowm"))
        {
            return;
        }

        foreach (String line in File.ReadAllLines(".\\trains.fowm"))
        {
            string[]   param = line.Split('|');
            TrainRoute route = new TrainRoute()
            {
                Name = param[0], Color = FOCommon.Utils.GetColor(param[1]), WayPoints = new List <TrainWaypoint>()
            };
            for (int i = 2; i < param.Length; i++)
            {
                string[] wpparam = param[i].Split(',');
                //TrainWaypoint wp = new TrainWaypoint(){Position=new Point(Int32.Parse(wpparam[0]), Int32.Parse(wpparam[1]))};
                TrainWaypoint wp = new TrainWaypoint()
                {
                    Position = new Point(Int32.Parse(wpparam[0]), (Int32.Parse(wpparam[1])))
                };
                route.WayPoints.Add(wp);
            }
            Routes.Add(route);
        }
    }
 public static Train GenerateTrain(TrainRoute route, DateTime departureTime)
 {
     return(new Train()
     {
         Route = route,
         DepartureTime = departureTime,
     });
 }
        public void Add(TrainRoute trainRoute)
        {
            var db = MongoDbManager <TrainRoute> .MongoDb(CollectionName);

            if (db != null)
            {
                db.Save(trainRoute);
            }
        }
Esempio n. 5
0
    public bool worldmap_coords_clicked(MouseEventArgs e, int x, int y)
    {
        int GameX = Display.PixelToGameCoords(x);
        int GameY = Display.PixelToGameCoords(y);

        if (Control.ModifierKeys == Keys.Control && e.Button == MouseButtons.Left)
        {
            ActionDone = true;

            if (Control.MouseButtons == MouseButtons.Right)
            {
                if (CurrentRoute == null)
                {
                    MessageBox.Show("No route currently constructed.");
                    return(false);
                }
                else
                {
                    CurrentRoute.WayPoints = new List <TrainWaypoint>();
                }
            }
            //MessageBox.Show("Left with ctrl.");
            if (CurrentRoute == null)
            {
                TrainRoute route = CreateRoute();
                if (route == null)
                {
                    return(false);
                }
                route.WayPoints = new List <TrainWaypoint>();
                CurrentRoute    = route;
                //Routes.Add(route);
            }
            TrainWaypoint wp = CreateWaypoint(GameX, GameY);
            if (wp == null || CurrentRoute == null)
            {
                return(false);
            }
            CurrentRoute.WayPoints.Add(wp);
            ScriptGlobal.RefreshWorldMap();
            return(true);
        }
        if (Control.ModifierKeys == Keys.Control && e.Button == MouseButtons.Right)
        {
            TrainWaypoint wp = GetWaypoint(GameX, GameY);
            if (wp == null)
            {
                return(false);
            }
            DeleteWaypoint(wp);
            ScriptGlobal.RefreshWorldMap();
            return(true);
        }

        return(false);
    }
Esempio n. 6
0
    public bool key_up(Form EventForm, KeyEventArgs e)
    {
        if (e.KeyCode == Keys.T && e.Control)
        {
            if (CurrentRoute == null)
            {
                return(false);
            }

            Routes.Add(CurrentRoute);
            MessageBox.Show(CurrentRoute.Name + " added to list.");
            CurrentRoute = null;
        }
        return(false);
    }
Esempio n. 7
0
        static async Task TramTrainTick()
        {
            try
            {
                if (API.NetworkIsHost())
                {
                    TrainRoute tr = tramTrainRoute;
                    if (!API.DoesEntityExist(tramTrainHandle))
                    {
                        Log.Info("Creating Tram");
                        tramTrainHandle = await TrainVehicle.Create(tr.Model, tr.TrainSpawn, tr.Npcs);

                        BaseScript.TriggerServerEvent("Trains.Update", API.VehToNet(valTrainHandle), API.VehToNet(bigTrainHandle), API.VehToNet(tramTrainHandle));
                    }
                    else
                    {
                        TrackSwitch nextSwitch = tr.Switches.OrderBy(o => Distance.EntityDistanceToSquared(tramTrainHandle, new Vector3(o.switchLoc.X, o.switchLoc.Y, o.switchLoc.Z))).First();
                        if (Distance.EntityDistanceToSquared(tramTrainHandle, new Vector3(nextSwitch.switchLoc.X, nextSwitch.switchLoc.Y, nextSwitch.switchLoc.Z)) < 25f)
                        {
                            Function.Call((Hash)0xE6C5E2125EB210C1, nextSwitch.switchId, nextSwitch.switchState1, nextSwitch.switchState2);
                            Function.Call((Hash)0x3ABFA128F5BF5A70, nextSwitch.switchId, nextSwitch.switchState1, nextSwitch.switchState2);
                        }
                        Vector4 nextStop = tr.Stops.OrderBy(o => Distance.EntityDistanceToSquared(tramTrainHandle, new Vector3(o.X, o.Y, o.Z))).First();
                        if (Distance.EntityDistanceToSquared(tramTrainHandle, new Vector3(nextStop.X, nextStop.Y, nextStop.Z)) < 5f)
                        {
                            API.SetTrainCruiseSpeed(tramTrainHandle, 0f);
                            await BaseScript.Delay(tr.Cooldown * 1000);

                            API.SetTrainCruiseSpeed(tramTrainHandle, (float)tr.CruiseSpeed);
                        }
                    }
                }
                else
                {
                    await BaseScript.Delay(60000);
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex.Message);
            }
            await BaseScript.Delay(1000);

            await Task.FromResult(0);
        }
Esempio n. 8
0
    private void DeleteWaypoint(TrainWaypoint wp)
    {
        List <TrainRoute> CheckRoutes = new List <TrainRoute>();

        CheckRoutes.AddRange(Routes);
        if (CurrentRoute != null)
        {
            CheckRoutes.Add(CurrentRoute);
        }
        for (int i = 0; i < CheckRoutes.Count; i++)
        {
            TrainRoute route = CheckRoutes[i];

            if (route.WayPoints.Contains(wp))
            {
                route.WayPoints.Remove(wp);
                return;
            }
        }
    }
Esempio n. 9
0
        public static int InsertTrainRoute(TrainRoute entity)
        {
            var sql = "INSERT INTO TrainRoute(TrainNumber,StartStationName,ArriveTime,StationTrainCode,StationName,TrainClassName,ServiceType,StartTime,StopoverTime,EndStationName,StationNo,IsEnabled) ";

            sql += "VALUES(@TrainNumber,@StartStationName,@ArriveTime,@StationTrainCode,@StationName,@TrainClassName,@ServiceType,@StartTime,@StopoverTime,@EndStationName,@StationNo,@IsEnabled)";

            var ps = new SqlParameter[]
            {
                new SqlParameter("@TrainNumber", ((object)entity.TrainNumber) ?? DBNull.Value),
                new SqlParameter("@StartStationName", ((object)entity.StartStationName) ?? DBNull.Value),
                new SqlParameter("@ArriveTime", ((object)entity.ArriveTime) ?? DBNull.Value),
                new SqlParameter("@StationTrainCode", ((object)entity.StationTrainCode) ?? DBNull.Value),
                new SqlParameter("@StationName", ((object)entity.StationName) ?? DBNull.Value),
                new SqlParameter("@TrainClassName", ((object)entity.TrainClassName) ?? DBNull.Value),
                new SqlParameter("@ServiceType", ((object)entity.ServiceType) ?? DBNull.Value),
                new SqlParameter("@StartTime", ((object)entity.StartTime) ?? DBNull.Value),
                new SqlParameter("@StopoverTime", ((object)entity.StopoverTime) ?? DBNull.Value),
                new SqlParameter("@EndStationName", ((object)entity.EndStationName) ?? DBNull.Value),
                new SqlParameter("@StationNo", ((object)entity.StationNo) ?? DBNull.Value),
                new SqlParameter("@IsEnabled", ((object)entity.IsEnabled) ?? DBNull.Value)
            };

            return(ExecuteNonQuery(sql, ps));
        }
Esempio n. 10
0
    private void LoadRoutes()
    {
        if(!File.Exists(".\\trains.fowm"))
            return;

        foreach(String line in File.ReadAllLines(".\\trains.fowm"))
        {
            string[] param = line.Split('|');
            TrainRoute route = new TrainRoute(){Name=param[0], Color=FOCommon.Utils.GetColor(param[1]), WayPoints=new List<TrainWaypoint>()};
            for(int i=2;i<param.Length;i++)
            {
                string[] wpparam = param[i].Split(',');
                //TrainWaypoint wp = new TrainWaypoint(){Position=new Point(Int32.Parse(wpparam[0]), Int32.Parse(wpparam[1]))};
                TrainWaypoint wp = new TrainWaypoint() { Position = new Point(Int32.Parse(wpparam[0]), (Int32.Parse(wpparam[1]))) };
                route.WayPoints.Add(wp);
            }
            Routes.Add(route);
        }
    }
Esempio n. 11
0
    public bool worldmap_coords_clicked(MouseEventArgs e, int x, int y)
    {
        int GameX = Display.PixelToGameCoords(x);
        int GameY = Display.PixelToGameCoords(y);

        if (Control.ModifierKeys == Keys.Control && e.Button == MouseButtons.Left)
        {
            ActionDone = true;

            if (Control.MouseButtons == MouseButtons.Right)
            {
                if (CurrentRoute == null)
                {
                    MessageBox.Show("No route currently constructed.");
                    return false;
                }
                else
                {
                    CurrentRoute.WayPoints = new List<TrainWaypoint>();
                }
            }
            //MessageBox.Show("Left with ctrl.");
            if (CurrentRoute == null)
            {
                TrainRoute route = CreateRoute();
                if (route == null)
                    return false;
                route.WayPoints = new List<TrainWaypoint>();
                CurrentRoute = route;
                //Routes.Add(route);
            }
            TrainWaypoint wp = CreateWaypoint(GameX, GameY);
            if (wp == null || CurrentRoute == null)
                return false;
            CurrentRoute.WayPoints.Add(wp);
            ScriptGlobal.RefreshWorldMap();
            return true;
        }
        if (Control.ModifierKeys == Keys.Control && e.Button == MouseButtons.Right)
        {
            TrainWaypoint wp = GetWaypoint(GameX, GameY);
            if (wp == null)
                return false;
            DeleteWaypoint(wp);
            ScriptGlobal.RefreshWorldMap();
            return true;
        }

        return false;
    }
Esempio n. 12
0
    public bool key_up(Form EventForm, KeyEventArgs e)
    {
        if (e.KeyCode == Keys.T && e.Control)
        {
            if (CurrentRoute == null)
                return false;

            Routes.Add(CurrentRoute);
            MessageBox.Show(CurrentRoute.Name + " added to list.");
            CurrentRoute = null;
        }
        return false;
    }
 /// <summary>
 /// There are no comments for TrainRoute in the schema.
 /// </summary>
 public void AddToTrainRoute(TrainRoute trainRoute)
 {
     base.AddObject("TrainRoute", trainRoute);
 }
 /// <summary>
 /// Create a new TrainRoute object.
 /// </summary>
 /// <param name="id">Initial value of ID.</param>
 public static TrainRoute CreateTrainRoute(global::System.Guid id)
 {
     TrainRoute trainRoute = new TrainRoute();
     trainRoute.ID = id;
     return trainRoute;
 }