Beispiel #1
0
        public Railcar(SharedTrain train, RailcarModel model, TrackPosition position) : base(train, model, position)
        {
            dummyObject = new WorldObject(321, Vector3.Zero)
            {
                Alpha             = 0,
                CollisionsEnabled = false,
            };
            dummyObject.SetStreamable(false);
            ClientRailManager m = (ClientRailManager)train.RailManager;

            trainVehicle = new Slipe.Client.Vehicles.Train(m.GetVehicleModelFromRailcar(model), Vector3.Zero)
            {
                Derailed = true
            };
            trainVehicle.SetStreamable(false);
            if (!model.IsEngine)
            {
                trainVehicle.OverrideLights = Slipe.Shared.Vehicles.OverrideLightState.ForcedOff;
            }
            trainVehicle.AttachTo(dummyObject, new Vector3(0, 0, model.Height), Vector3.Zero);

            FrontPosition = position;

            random      = new Random();
            OnNodePass += PlaySoundEffect;
        }
Beispiel #2
0
 public void UpdateProgress(TrackPosition position)
 {
     try
     {
         if (nowPlayingInfo == null)
         {
             return;
         }
         if (Math.Abs(position.CurrentTime - lastTime) < 1)
         {
             return;
         }
         lastTime = position.CurrentTime;
         if (artwork != null && (int)lastTime % 10 == 0)
         {
             nowPlayingInfo.Artwork = artwork;
         }
         nowPlayingInfo.ElapsedPlaybackTime = position.CurrentTime;
         nowPlayingInfo.PlaybackDuration    = position.Duration;
         App.RunOnMainThread(() => MPNowPlayingInfoCenter.DefaultCenter.NowPlaying = nowPlayingInfo);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex);
     }
 }
Beispiel #3
0
        public void HandleTrainSync(TrainSyncRpc rpc)
        {
            for (int i = 0; i < rpc.TrainCount; i++)
            {
                string[]       carData = rpc.TrainCars[i].Split("-");
                RailcarModel[] models  = new RailcarModel[carData.Length];
                for (int j = 0; j < carData.Length; j++)
                {
                    models[j] = Models[int.Parse(carData[j])];
                }

                Train train;
                if (i >= Trains.Count)
                {
                    train = new Train(this, models[i], TrackPosition.FromString(this, rpc.TrainPositions[i]));
                    for (int j = 1; j < models.Length; j++)
                    {
                        train.AddRailcar(models[j]);
                    }
                }
                else
                {
                    train = (Train)Trains[i];
                }

                train.UpdatePosition(TrackPosition.FromString(this, rpc.TrainPositions[i]));
                train.Speed        = rpc.TrainSpeeds[i];
                train.Acceleration = rpc.TrainAccelerations[i];
            }

            for (int i = 0; i < rpc.SwitchInfo.Length; i++)
            {
                Switches[i].SwitchPosition = rpc.SwitchInfo[i];
            }
        }
Beispiel #4
0
        public TrenElement AddTrack(TrenColor color, TrackPosition position, int length, TrenElement[] cities)
        {
            if (State != StateMachineStates.Setup)
            {
                throw new Exception("Must be in setup state");
            }
            if (cities == null || cities.Length == 0)
            {
                throw new Exception("Must provide a valid list of cities");
            }

            // create a track
            var row = Elements.Count;

            Elements.Add(new List <TrenElement>());
            var track = new TrenElement()
            {
                Type = TrenElementType.Track, Color = color, Position = position, Length = length, Row = row, Column = Elements[row].Count, InUse = true
            };

            // add the connecting cities
            for (int i = 0; i < cities.Length; i++)
            {
                if (cities[i].Type != TrenElementType.City)
                {
                    throw new Exception("Must provide valid cities");
                }
                track.Connections.Add(cities[i]);
            }
            // add
            Elements[row].Add(track);
            return(track);
        }
Beispiel #5
0
        internal void UpdatePosition(TrackPosition newPosition)
        {
            float d = Vector3.Distance((Vector3)FrontPosition, (Vector3)newPosition);

            if (d > Speed / 2)
            {
                FrontPosition = newPosition;
            }
        }
Beispiel #6
0
        public Train(ServerRailManager manager, RailcarModel engineModel, TrackPosition position) : base(manager, engineModel, position)
        {
            Speed        = 0f;
            Acceleration = 0.5f;
            MaxSpeed     = 8f;
            Railcar engine = new Railcar(this, engineModel, position);

            Railcars.Add(engine);
        }
    public List <TrackPosition> TilesOccupied(TrackPosition relative_to_position, Direction relative_to_direction)
    {
        List <TrackPosition> ret = new List <TrackPosition>();

        foreach (TrackPosition tp in relative_tiles_occupied)
        {
            ret.Add(new TrackPosition((Vector2)(Quaternion.Euler(0, 0, (360 - (int)relative_to_direction * 90)) * tp.position) + NextStartingPoint(relative_to_direction, relative_to_position.position), tp.GetHeight()));
        }
        return(ret);
    }
 void SetColliderPosition(TrackPosition tp)
 {
     if (tp.GetHeight() == TrackPosition.Height.middle)
     {
         checker.center = new Vector3(tp.position.x, 0, tp.position.y);
         checker.size   = Vector3.one * .999f;
     }
     else
     {
         checker.center = new Vector3(tp.position.x, tp.GetHeight() == TrackPosition.Height.over ? 6.0f : -6.0f, tp.position.y);
         checker.size   = new Vector3(.999f, 10.999f, .999f);
     }
 }
Beispiel #9
0
    public IEnumerator GenerateTrackPieces()
    {
        while (true)
        {
            yield return(null);

            if (future_track_pieces.Count < lead)
            {
                TrackPosition gen_at = GetNextGenPosition();
                if (other_possible_pieces.ContainsKey(gen_at))
                {
                    List <TrackRarity> possible_pieces = other_possible_pieces[gen_at].pieces;
                    TrackPiece         selected        = null;
                    if (possible_pieces.Count > 0)
                    {
                        // If possible pieces remain try one
                        float rand  = Random.Range(0, other_possible_pieces[gen_at].rarity);
                        int   count = -1;

                        float rarity_to_remove = 0;
                        while (rand > 0)
                        {
                            count++;
                            selected         = possible_pieces[count].piece;
                            rand            -= possible_pieces[count].rarity;
                            rarity_to_remove = possible_pieces[count].rarity;
                        }
                        possible_pieces.RemoveAt(count);
                        other_possible_pieces[gen_at].rarity -= rarity_to_remove;

                        if (PieceCanFit(selected))
                        {
                            // If can fit add it to future pieces
                            AddPiece(selected);
                        }
                    }
                    else
                    {
                        // If no possible pieces remain backtrack
                        RemoveLastPiece();
                    }
                }
                else
                {
                    // if gen at does not exist add it to the gen with all track_objects as possible;
                    other_possible_pieces.Add(gen_at, new TrackRarityList(track_objects));
                }
            }
        }
    }
    IEnumerator Check()
    {
        while (positions_to_check.Count > 0)
        {
            TrackPosition to_check = positions_to_check[0];
            positions_to_check.RemoveAt(0);

            if (!checked_positions.ContainsKey(to_check))
            {
                collision_detected = false;
                yield return(CheckPosition(to_check));

                checked_positions.Add(to_check, collision_detected);

                if (collision_detected)
                {
                    positions_to_check.AddRange(AdjacentPositions(to_check));
                }

                GameObject new_square = GameObject.CreatePrimitive(PrimitiveType.Cube);
                new_square.transform.position   = checker.center;
                new_square.transform.localScale = checker.size;

                if (collision_detected)
                {
                    new_square.GetComponent <MeshRenderer>().material.color = new Color(0, 1, 0, 0.5f);
                }
                else
                {
                    new_square.GetComponent <MeshRenderer>().material.color = new Color(1, 0, 0, 0.5f);
                }

                new_square.GetComponent <Collider>().enabled = false;
            }
        }

        List <TrackPosition> positions = new List <TrackPosition>();

        foreach (TrackPosition pos in checked_positions.Keys)
        {
            if (checked_positions[pos])
            {
                positions.Add(pos);
            }
        }

        piece_to_check.ForceSetRelativeTiles(positions);
    }
Beispiel #11
0
        public async Task <bool> PostGPSPosition(double latitude, double longitude, int trackId)
        {
            TrackPosition latestPosition    = new TrackPosition();
            var           postBody          = new { sid = 1, uid = trackId, longitude = longitude, latitude = latitude, recoDt = DateTime.Now };
            var           customWebResponse = await HttpWebRequestHelper.PostHttpWebResponse(Constants.PostCurrentPositionAPI, postBody);

            if (customWebResponse != null)
            {
                if (customWebResponse.Response.StatusCode == System.Net.HttpStatusCode.OK)
                {
                    // latestPosition = this.ConvertResponseToTrackPosition(customWebResponse.ResponseData);
                }
            }

            return(true);
        }
    IEnumerator CheckPosition(TrackPosition p)
    {
        checker.enabled = true;
        Nudge();

        SetColliderPosition(p);
        float time = 0;

        while (time < 0.15f && !collision_detected)
        {
            yield return(null);

            time += Time.deltaTime;
        }
        checker.enabled = false;
    }
    List <TrackPosition> AdjacentPositions(TrackPosition pos)
    {
        List <TrackPosition> to_ret = new List <TrackPosition>();

        to_ret.Add(pos + new Vector2(0, -1));
        to_ret.Add(pos + new Vector2(0, 1));
        to_ret.Add(pos + new Vector2(-1, 0));
        to_ret.Add(pos + new Vector2(1, 0));

        if (pos.GetHeight() == TrackPosition.Height.middle)
        {
            to_ret.Add(new TrackPosition(pos.position, TrackPosition.Height.over));
            to_ret.Add(new TrackPosition(pos.position, TrackPosition.Height.under));
        }
        else
        {
            to_ret.Add(new TrackPosition(pos.position, TrackPosition.Height.middle));
        }

        return(to_ret);
    }
    public void Init(TrackPosition start, Direction direction, float track_scale)
    {
        position = start.position;

        start_direction = direction;

        List <TrackPosition> new_track_position = new List <TrackPosition>();

        int angle = 360 - 90 * (int)direction;

        if (direction != Direction.north)
        {
            foreach (TrackPosition tp in relative_tiles_occupied)
            {
                tp.RotateAroundOrigin(angle);
            }
            _end_position.RotateAroundOrigin(angle);
        }

        transform.position      = new Vector3(start.position.x * track_scale, 0, start.position.y * track_scale);
        transform.localRotation = Quaternion.Euler(0, angle * -1, 0);
        transform.localScale    = new Vector3(track_scale, track_scale, track_scale);
    }
Beispiel #15
0
        private List <TrackPosition> ConvertResponseToTrackPosition(string response)
        {
            List <TrackPosition> latestPositions = new List <TrackPosition>();

            if (!string.IsNullOrEmpty(response))
            {
                var jsonResponse = JArray.Parse(response);

                if (jsonResponse.Any())
                {
                    foreach (var item in jsonResponse)
                    {
                        var latestPosition = new TrackPosition();
                        latestPosition.Longitude   = item["longitude"].Value <double>();
                        latestPosition.Latitude    = item["latitude"].Value <double>();
                        latestPosition.DisplayName = "Test API Location";

                        latestPositions.Add(latestPosition);
                    }
                }
            }
            else//Test
            {
                var lon = 76.31947642;
                var lat = 9.98954503;
                for (int i = 0; i < 5; i++)
                {
                    var latestPosition = new TrackPosition();
                    latestPosition.Longitude   = lon + (i * 0.100);
                    latestPosition.Latitude    = lat + (i * 0.100);;
                    latestPosition.DisplayName = "Test Location";
                    latestPositions.Add(latestPosition);
                }
            }
            return(latestPositions);
        }
Beispiel #16
0
 public void SetCurrentTrackPosition(TrackPosition data)
 {
     timeLabel.Text          = data.CurrentTimeString;
     remainingTimeLabel.Text = data.RemainingTimeString;
     slider.SliderProgress   = data.Percent;
 }
Beispiel #17
0
 public void SetCurrentTrackPosition(TrackPosition data)
 {
     footer.SetCurrentTrackPosition(data);
 }
 internal void SetPlaybackPosition(TrackPosition data)
 {
     slider.SliderProgress = data.Percent;
     timeLabel.Text        = data.CurrentTimeString;
     timeRemaingLabel.Text = data.RemainingTimeString;
 }
 public void MoveToPosition(TrackPosition newTrackPosition)
 {
     if ((newTrackPosition.position >= 0.0d) && (newTrackPosition.position < 1.0d))
     {
         this.nativeVlc.Position = newTrackPosition.position;
         if (this.IsPaused)
         {
             this.usingPausedPosition = true;
             this.pausedTime = newTrackPosition.time;
             this.pausedPosition = newTrackPosition.position;
             this.shuttleSeconds = 0;
         }
     }
 }
 private void Form1_Load(object sender, EventArgs e)
 {
     timer1.Start();
     TrackPosition.Start();
 }
Beispiel #21
0
        public Train(ClientRailManager manager, RailcarModel engineModel, TrackPosition position) : base(manager, engineModel, position)
        {
            Railcar engine = new Railcar(this, engineModel, position);

            Railcars.Add(engine);
        }
Beispiel #22
0
 public void ProcCurrentTrackPositionChanged(TrackPosition position)
 {
     CurrentTrackPositionChanged?.InvokeOnMainThread(this, position);
 }
Beispiel #23
0
 public Railcar(Train train, RailcarModel model, TrackPosition position) : base(train, model, position)
 {
 }