Exemplo n.º 1
0
 public Fleet(Fleet source)
 {
     Position = source.Position;
     Owner = source.Owner;
     Origin = source.Origin;
     Destination = source.Destination;
     Count = source.Count;
     Rotation = source.Rotation;
     Positions = source.Positions;
 }
Exemplo n.º 2
0
        public void SendFleet(int Ammount, Planet Origin, Planet Destination)
        {
            if (Origin.Id == Destination.Id)
                return;
            if (Origin.Forces < Ammount)
                return;
            Origin.Forces -= Ammount;

            Fleet fleet = new Fleet();
            fleet.Owner = Origin.Owner;
            //Put the ship on the edge
            Vector2 Normalized = Destination.Position - Origin.Position;
            Normalized.Normalize();
            fleet.Rotation = (float)Math.Atan2(Normalized.Y, Normalized.X) + MathHelper.ToRadians(90);
            Normalized *= Origin.PlanetSize * 64;

            fleet.Position = Origin.Position + Normalized;
            fleet.Origin = Origin.Id;
            fleet.Destination = Destination.Id;
            fleet.Count = Ammount;

            int ExtraShipCount = 0;
            if (fleet.Count - 10 >= 10)
                ExtraShipCount = (fleet.Count - 10) / 10;
            fleet.Positions = new Vector2[ExtraShipCount];
            Normalized.Normalize();

            for (int i = 0; i < ExtraShipCount; i++)
            {
                float Angle = MathHelper.ToRadians((float)(Manager.rnd.Next(360) + Manager.rnd.NextDouble()));
                float Distance = 8 + (float)Math.Sqrt(Manager.rnd.NextDouble()) * ((1 + (float)Math.Sqrt(ExtraShipCount) / 2) * 8);
                fleet.Positions[i] = new Vector2((float)Math.Cos(Angle) * Distance, (float)Math.Sin(Angle) * Distance);

                foreach (Vector2 p in fleet.Positions)
                {
                    if (p == null || p == fleet.Positions[i])
                        continue;

                    if (Vector2.Distance(p, fleet.Positions[i]) < 16)
                    {
                        Angle = MathHelper.ToRadians((float)(Manager.rnd.Next(360) + Manager.rnd.NextDouble()));
                        Distance = 8 + (float)Math.Sqrt(Manager.rnd.NextDouble()) * ((1 + (float)Math.Sqrt(ExtraShipCount) / 2) * 8);
                        fleet.Positions[i] = new Vector2((float)Math.Cos(Angle) * Distance, (float)Math.Sin(Angle) * Distance);
                    }
                }
            }

            Fleets.Add(fleet);
        }