public void AddPlanet(Planet planet) { LeadingState.Planets.Add(planet); TrailingState0.Planets.Add(new Planet(planet)); TrailingState1.Planets.Add(new Planet(planet)); TrailingState2.Planets.Add(new Planet(planet)); TrailingState3.Planets.Add(new Planet(planet)); TrailingState4.Planets.Add(new Planet(planet)); }
public Planet(Planet source) { Position = source.Position; Texture = source.Texture; PlanetSize = source.PlanetSize; Id = source.Id; Owner = source.Owner; Forces = source.Forces; HasPeople = source.HasPeople; Growth = source.Growth; GrowthCounter = source.GrowthCounter; GrowthReset = source.GrowthReset; SelectionRotation = source.SelectionRotation; }
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); }
public void SendFleet(int Ammount, Planet Origin, Planet Destination,int Tick) { SendFleet(Ammount, Origin.Id, Destination.Id,Tick); }
private void SendFleet(Planet origin, Planet destination) { if (origin.Owner != Player) return; if (origin.Id == destination.Id) return; SendF.Write(origin.Id); SendF.Write(destination.Id); }
private List<Planet> LoadMap(string map) { List<Planet> mapPlanets = new List<Planet>(); IsolatedStorageFileStream fs = new IsolatedStorageFileStream(map, System.IO.FileMode.Open, storage); int LargeNotPopulated = 3; int LargePopulated = 4; int MediumNotPopulated = 2; int MediumPopulated = 3; int SmallNotPopulated = 3; int SmallPopulated = 3; Random rnd = new Random(); XmlReader xmlReader = XmlReader.Create(fs); while (xmlReader.Read()) { /*Read planet header*/ if (xmlReader.LocalName == "Planet" && xmlReader.IsStartElement()) { /*Read the ID element*/ xmlReader.Read(); xmlReader.MoveToElement(); xmlReader.ReadStartElement("ID"); int ID = xmlReader.ReadContentAsInt(); /*Read the owner element*/ xmlReader.Read(); xmlReader.MoveToElement(); xmlReader.ReadStartElement("Owner"); string owner = xmlReader.ReadContentAsString(); /*Read the forces element*/ xmlReader.Read(); xmlReader.MoveToElement(); xmlReader.ReadStartElement("Forces"); int forces = xmlReader.ReadContentAsInt(); /*Read the growth element*/ xmlReader.Read(); xmlReader.MoveToElement(); xmlReader.ReadStartElement("Growth"); int growth = xmlReader.ReadContentAsInt(); /*Read the growth cooldown element*/ xmlReader.Read(); xmlReader.MoveToElement(); xmlReader.ReadStartElement("GrowthCooldown"); int growthcd = xmlReader.ReadContentAsInt(); /*Read the size element*/ xmlReader.Read(); xmlReader.MoveToElement(); xmlReader.ReadStartElement("Size"); float size = xmlReader.ReadContentAsFloat(); /*Read the people element*/ xmlReader.Read(); xmlReader.MoveToElement(); xmlReader.ReadStartElement("HasPeople"); bool hasppl = xmlReader.ReadContentAsBoolean(); /*Read the Position element*/ xmlReader.Read(); xmlReader.MoveToElement(); xmlReader.ReadStartElement("Position"); Microsoft.Xna.Framework.Vector2 Position = new Microsoft.Xna.Framework.Vector2(); /*Read the X element*/ xmlReader.Read(); xmlReader.MoveToElement(); xmlReader.ReadStartElement("X"); Position.X = xmlReader.ReadContentAsInt(); /*Read the Y element*/ xmlReader.Read(); xmlReader.MoveToElement(); xmlReader.ReadStartElement("Y"); Position.Y = xmlReader.ReadContentAsInt(); Planet p = new Planet(); p.Id = ID; p.Position = Position; p.Growth = growth; p.GrowthCounter = growthcd; p.GrowthReset = growthcd; p.Owner = (VelesConflict.Gameplay.PlayerType)Enum.Parse(typeof(VelesConflict.Gameplay.PlayerType), owner, false); p.Forces = forces; p.PlanetSize = size; p.HasPeople = hasppl; PlanetSize pz = PlanetSize.Large; //Determine the load location string TextureLocation = "Graphics/Planets/"; if (p.PlanetSize >= 0.6) { pz = PlanetSize.Large; } else { if (rnd.NextDouble() < 0.35) pz = PlanetSize.Small; else pz = PlanetSize.Medium; } TextureLocation += pz.ToString() + "/"; switch (pz) { case PlanetSize.Large: if (p.HasPeople) { int Number = rnd.Next(1, (LargePopulated + 1)); TextureLocation += "Populated/" + Number.ToString(); } else { int Number = rnd.Next(1, (LargeNotPopulated + 1)); TextureLocation += "NotPopulated/" + Number.ToString(); } break; case PlanetSize.Medium: if (p.HasPeople) { int Number = rnd.Next(1, (MediumPopulated + 1)); TextureLocation += "Populated/" + Number.ToString(); } else { int Number = rnd.Next(1, (MediumNotPopulated + 1)); TextureLocation += "NotPopulated/" + Number.ToString(); } break; case PlanetSize.Small: if (p.HasPeople) { int Number = rnd.Next(1, (SmallPopulated + 1)); TextureLocation += "Populated/" + Number.ToString(); } else { int Number = rnd.Next(1, (SmallNotPopulated + 1)); TextureLocation += "NotPopulated/" + Number.ToString(); } break; } p.Texture = Content.Load<Texture2D>(TextureLocation); mapPlanets.Add(p); } } fs.Close(); return mapPlanets; }