示例#1
0
        void ParseCommand(string command)
        {
            if (command == null)
                return;
            try
            {
                string[] Split = command.Split(' ');
                switch (Split[0])
                {
                    case "+ADD":
                        {
                            //Id positionX positionY size count owner growthReset growthRate
                            Planet planet = new Planet();
                            planet.Id = int.Parse(Split[1]);
                            planet.Position = new Microsoft.Xna.Framework.Vector2(float.Parse(Split[2]), float.Parse(Split[3]));
                            planet.PlanetSize = float.Parse(Split[4]);
                            planet.Forces = int.Parse(Split[5]);
                            planet.Owner = (PlayerType)int.Parse(Split[6]);
                            planet.GrowthCounter = planet.GrowthReset = int.Parse(Split[7]);
                            planet.Growth = int.Parse(Split[8]);
                            lock (GameBase.GameManager)
                                GameBase.GameManager.State.Planets.Add(planet);
                        }
                        break;
                    case "+UPDATE":
                        {
                            int Id = int.Parse(Split[1]);
                            lock (GameBase.GameManager)
                            {
                                Planet planet = GameBase.GameManager.State.Planets.First(p => p.Id == Id);
                                planet.Position = new Microsoft.Xna.Framework.Vector2(float.Parse(Split[2]), float.Parse(Split[3]));
                                planet.PlanetSize = float.Parse(Split[4]);
                                planet.Forces = int.Parse(Split[5]);
                                planet.Owner = (PlayerType)int.Parse(Split[6]);
                                planet.GrowthCounter = planet.GrowthReset = int.Parse(Split[7]);
                                planet.Growth = int.Parse(Split[8]);
                            }
                        }
                        break;
                    case "+DELETE":
                        //Id
                        {
                            int Id = int.Parse(Split[1]);
                            Planet toRemove = GameBase.GameManager.State.Planets.First(p => p.Id == Id);
                            lock(GameBase.GameManager)
                                GameBase.GameManager.State.Planets.Remove(toRemove);
                        }
                        break;
                    case "+CLEAR":
                        lock (GameBase.GameManager)
                        {
                            GameBase.GameManager.State.Planets.Clear();
                        }
                        break;
                    case "+PLAY":
                        GameBase Game=Globals.Engine as GameBase;
                        Game.EditorStartGame();
                        break;
                }
            }
            catch(Exception e)
            {

            }
        }
示例#2
0
        void LoadMission(Mission mission)
        {
            GameActions = 0;
            GameTimeSpent = TimeSpan.Zero;
            spriteBatch.Begin();
            spriteBatch.Draw(Splash, Vector2.Zero, Color.White);
            spriteBatch.End();
            GraphicsDevice.Present();
            RCS.Release(TimeSpan.Zero);
            LevelContentManager = new ContentManager(this, "Content");
            GameManager = new GameManager();
            GameScript = new AtomScript(false, new Assembly[] { Assembly.GetExecutingAssembly() });
            GameScript.Pause = false;
            string map = "";
            Random rnd = new Random();
            //Properly resolve the mission address
            if (mission.Map.StartsWith("XAP\\"))
            {
                //internal content
                map = mission.Map.Remove(0, 4);
            }

            int LargeNotPopulated = 3;
            int LargePopulated = 4;

            int MediumNotPopulated = 2;
            int MediumPopulated = 3;

            int SmallNotPopulated = 3;
            int SmallPopulated = 3;

            List<Planet> mapPlanets = new List<Planet>();
            XmlReader xmlReader = XmlReader.Create(map);
            xmlReader.ReadStartElement();

            xmlReader.Read();
            xmlReader.MoveToElement();
            xmlReader.ReadStartElement("Width");
            Width = xmlReader.ReadContentAsInt();

            xmlReader.Read();
            xmlReader.MoveToElement();
            xmlReader.ReadStartElement("Height");
            Height = xmlReader.ReadContentAsInt();

            if (Width > 800 && Height > 480)
            {
                SetupCameraBig();
            }
            else
            {
                SetupCameraSmall();
            }

            xmlReader.Read();
            xmlReader.MoveToElement();
            xmlReader.ReadStartElement("Format");
            int Format = xmlReader.ReadContentAsInt();

            xmlReader.Read();
            xmlReader.MoveToElement();
            xmlReader.ReadStartElement("HasScript");
            bool HasScript = xmlReader.ReadContentAsBoolean();
            if (HasScript)
            {
                xmlReader.ReadToFollowing("Script");
                GameScript.Load(xmlReader);
            }
            #region Load Map
            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 = (PlayerType)Enum.Parse(typeof(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 = LevelContentManager.Load<Texture2D>(TextureLocation);
                    mapPlanets.Add(p);
                }

            }
            #endregion
            FleetTexture1 = LevelContentManager.Load<Texture2D>("Graphics/Fleets/3");
            FleetTexture2 = LevelContentManager.Load<Texture2D>("Graphics/Fleets/5");
            int ParalaxFolder = rnd.Next(1, 6);
            ParalaxLayer1 = LevelContentManager.Load<Texture2D>(string.Format("Graphics/Backgrounds/{0}/1", ParalaxFolder));
            ParalaxLayer2 = LevelContentManager.Load<Texture2D>(string.Format("Graphics/Backgrounds/{0}/2", ParalaxFolder));
            ParalaxLayer3 = LevelContentManager.Load<Texture2D>(string.Format("Graphics/Backgrounds/{0}/3", ParalaxFolder));
            GameManager.State.Planets.AddRange(mapPlanets);
            GameScript.LoadScript();
            GameScript.Pause = false;
            xmlReader.Dispose();
        }
示例#3
0
        void OnLoad(object sender, OnInput e)
        {
            int NewID = (int)this.Inputs["ID"].Data;
            if (Planet != null)
            {
                Planet.Captured -= OnCaptured;
            }
            Planet = (from P in VelesConflict.Shared.GameBase.GameManager.State.Planets where P.Id == NewID select P).First();
            Planet.Captured += OnCaptured;

            this.Outputs["Forces"].Call((int)Planet.Forces);
            this.Outputs["Owner"].Call((int)Planet.Owner);
            this.Outputs["Position"].Call(Planet.Position);
            ForcesPrevious = Planet.Forces;
        }
示例#4
0
        public void SendFleet(int Ammount,PlayerType Type, Vector2 Origin, Planet Destination)
        {
            Fleet fleet = new Fleet();
            fleet.Owner = Type;
            //Put the ship on the edge
            Vector2 Normalized = Destination.Position - Origin;
            Normalized.Normalize();
            fleet.Rotation = (float)Math.Atan2(Normalized.Y, Normalized.X) + MathHelper.ToRadians(90);

            fleet.Position = Origin;
            fleet.Origin = null;
            fleet.Destination = Destination;
            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)(rnd.Next(360) + rnd.NextDouble()));
                float Distance = 8 + (float)Math.Sqrt(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)(rnd.Next(360) + rnd.NextDouble()));
                        Distance = 8 + (float)Math.Sqrt(rnd.NextDouble()) * ((1 + (float)Math.Sqrt(ExtraShipCount) / 2) * 8);
                        fleet.Positions[i] = new Vector2((float)Math.Cos(Angle) * Distance, (float)Math.Sin(Angle) * Distance);
                    }
                }
            }

            State.Fleets.Add(fleet);
        }