Пример #1
0
        public static Vehicle FindNearestVehicle(Vector3D pos)
        {
            Vehicle nearest = null;

            double smallest = double.MaxValue;


            foreach (Vehicle vehicle in Manager.Instance.Registered())
            {
                Bawl bawl = vehicle as Bawl;

                if (bawl == null)
                {
                    continue;
                }

                double distance = pos.DistanceSq(bawl.Position);

                if (smallest > distance)
                {
                    smallest = distance;
                    nearest  = bawl;
                }
            }

            return(nearest);
        }
Пример #2
0
        public static Vehicle FindNearestNeighbour(Vector3D pos)
        {
            Vehicle nearest = null;

            double smallest = double.MaxValue;

            World.PrepareVehicleNeighbours(GetVehiclePartition(pos));

            foreach (Partition <Vehicle> p in World.CurrentNeighbours)
            {
                foreach (Vehicle vehicle in p.Members)
                {
                    Bawl bawl = vehicle as Bawl;

                    if (bawl == null)
                    {
                        continue;
                    }

                    double distance = pos.DistanceSq(bawl.Position);

                    if (smallest > distance)
                    {
                        smallest = distance;
                        nearest  = bawl;
                    }
                }
            }

            return(nearest);
        }
Пример #3
0
 public static void MiniMapDrawBawl(Bawl bawl)
 {
     s_gWorldViewBuffer.DrawRectangle(
         bawl.Pen,
         (float)(bawl.Position.I / World.MiniMapRatioX),
         (float)(bawl.Position.J / World.MiniMapRatioY),
         1, 1);
 }
Пример #4
0
        public static void HighlightNearestBawl()
        {
            Bawl nearest = (Bawl)Entities.Pointer.NearestEntity;

            if (nearest != null)
            {
                Renderer.DrawEllipse(
                    nearest.Position,
                    (int)nearest.Size + 6,
                    Pens.Black,
                    Brushes.Silver);
            }
        }
Пример #5
0
        public static void Randomize()
        {
            for (int i = 0; i < 2000; i++)
            {
                double r = s_Random.NextDouble();

                Bawl b = new Bawl(
                    new Vector3D(s_Random.Next((int)Settings.WorldSize.I), s_Random.Next((int)Settings.WorldSize.J), 0),
                    new Vector3D(s_Random.NextDouble(), s_Random.NextDouble(), 0),
                    new Vector3D(0, 0, 0),
                    new Vector3D(0, 0, 0),
                    new Vector3D(0, 0, 0),
                    0,
                    Pens.Yellow,
                    Renderer.Yellow,
                    0);

                if (r < 0.01)
                {
                    b.Mass  = BawlMass.Huge;
                    b.Size  = BawlSize.Huge;
                    b.Brush = Brushes.Yellow;
                }
                else if (r < 0.2)
                {
                    b.Mass  = BawlMass.Large;
                    b.Size  = BawlSize.Large;
                    b.Brush = Brushes.Purple;
                }
                else if (r < 0.6)
                {
                    b.Mass  = BawlMass.Medium;
                    b.Size  = BawlSize.Medium;
                    b.Brush = Brushes.Green;
                }
                else
                {
                    b.Mass  = BawlMass.Small;
                    b.Size  = BawlSize.Small;
                    b.Brush = Brushes.Pink;
                }


                b.FSM.Change(State.Bawl.Float.Instance);

                Manager.Instance.Register(b);
                World.AddVehicle(b);
            }
        }
Пример #6
0
        public EntryBawl(Group group, string name, Bawl bawl)
            : base(group, name, bawl)
        {
            m_Bawl = bawl;

            m_Width  = (int)BawlSize.Huge + m_Group.PadX;
            m_Height = (int)BawlSize.Huge + m_Group.PadY;

            m_Key = m_Bawl.GetHashCode();

            m_Brush = Renderer.InitializeGradientBrush(
                m_Group.EntryColor.Color,
                m_Group.X + m_Group.PadX,
                m_Group.Y + m_Group.PadY,
                m_Width, m_Height);
        }
Пример #7
0
        public static void ResolveCollision(Vehicle vehicle)
        {
            Bawl bA = vehicle as Bawl;

            if (bA == null)
            {
                return;
            }

            World.PrepareVehicleNeighbours(bA.Partition);

            foreach (Partition <Vehicle> partition in World.CurrentNeighbours)
            {
                foreach (Vehicle vehicle2 in partition.Members)
                {
                    Bawl bB = vehicle2 as Bawl;

                    if (bB == null)
                    {
                        continue;
                    }

                    if (bA == bB)
                    {
                        continue;
                    }

                    Vector3D distance = bA.Position - bB.Position;

                    double length = distance.Magnitude();

                    Vector3D n = distance.Normalized();

                    double overlap = ((double)(int)bB.Size + (double)(int)bA.Size) / 2 - length;

                    if (overlap >= 0)
                    {
                        if (
                            bA.Mass < bB.Mass ||
                            ((bA.Mass == bB.Mass) && (bA.Velocity > bB.Velocity))
                            )
                        {
                            bA.PreviousPosition = bA.Position;
                            bA.Position        += n * overlap;
                        }
                        else if (
                            bB.Mass < bA.Mass ||
                            ((bB.Mass == bA.Mass) && (bB.Velocity > bA.Velocity))
                            )
                        {
                            bB.PreviousPosition = bB.Position;
                            bB.Position        -= n * overlap;
                        }
                        else
                        {
                            bA.PreviousPosition = bA.Position;
                            bB.PreviousPosition = bB.Position;
                            bA.Position        += n * overlap / 2;
                            bB.Position        -= n * overlap / 2;
                        }

                        Vector3D vAB = bA.Velocity - bB.Velocity;

                        double vRel = vAB.Dot(n);

                        if (vRel < -Settings.VectorMinMagnitude)
                        {
                            double e = 1.0;

                            double j = ((-(1.0 + e) * vRel) / (1.0 / bA.Mass + 1.0 / bB.Mass));

                            bA.Velocity += n * (j / bA.Mass);
                            bB.Velocity -= n * (j / bB.Mass);

                            bA.Velocity.Truncate(bA.MaxSpeed);
                            bB.Velocity.Truncate(bB.MaxSpeed);
                        }
                    }
                }
            }
        }