Exemple #1
0
        public void ProcessTurn(GameManager gm,GameTime gt)
        {
            SinceLastCommand += gt.ElapsedGameTime;
            if (gm.State.AIPlanets.Count == 0)
                return;
            int Difficulty = (int)GameBase.playerData.Difficulty;
            if (Difficulty == 1 && SinceLastCommand.TotalSeconds < 5)
            {

                return;
            }

            GenerateActionPlan(gm);
            ImplementActionPlan(gm);
        }
Exemple #2
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            object Di = DeviceExtendedProperties.GetValue("DeviceUniqueId");
            DeviceID = GetSHA2((byte[])Di);
            playerData = new PlayerData();
            playerData.Load();
            playerData.ReportingEnabled = true;
            base.Initialize();
            base.OnUpdateStart += new Action<GameTime>(fOnUpdateStart);
            base.OnUpdateEnd += new Action<GameTime>(fOnUpdateEnd);
            base.OnDrawStart += new Action<GameTime>(fOnDrawStart);
            base.OnDrawEnd += new Action<GameTime>(fOnDrawEnd);

            GameManager = new GameManager();

            adManager.Initialize();
            TryPushStatistics();

            StartAgent();
        }
Exemple #3
0
        void OnGameEnd()
        {
            if (playerData.ReportingEnabled)
            {
                VelesConflictReporting.GameUsageStastics gus = new VelesConflictReporting.GameUsageStastics();
                gus.Actions = GameActions;
                gus.Map = selectedMission.Map;
                gus.TimeSpent = GameTimeSpent;
                gus.Difficulty = (int)playerData.Difficulty;
                gus.DeviceID = DeviceID;
                gus.Winner = GameManager.GetLooser() == PlayerType.Player2 ? 1 : 2;
                lock (GameUsage)
                    GameUsage.Add(gus);
            }
            GameActions = 0;
            GameTimeSpent = TimeSpan.Zero;
            Manager.Enabled = true;
            MainMenuContract.Enabled = true;
            SinglePlayerContract.Enabled = false;
            GameScript.Dispose();
            GameScript = null;
            GameState = GameState.Menu;
            LevelContentManager.Unload();
            LevelContentManager.Dispose();

            textSettings.Scale = 1;
            textSettings.Origin = Vector2.Zero;
            textSettings.Width = 200;
            textSettings.Offset = new Vector2(545, 50);
            textSettings.Depth = 0.49f;
            //Select the next mission
            if (GameManager.GetLooser() == PlayerType.Player2)
            {
                Control LastControl = Manager.Menues["Mission"].Controls.Last(control => control.Tag == selectedMission);
                LastControl.Color = Color.White;
                int Index = Manager.Menues["Mission"].Controls.LastIndexOf(LastControl) + 1;
                int Offset = Manager.Menues["Mission"].Controls.IndexOf(Manager.Menues["Mission"].Controls.First(control => control.Tag is Mission));
                int Progress = EpisodeProgressCounter + selectedEpisode.Missions.IndexOf(selectedMission) + 2;
                if (Progress > playerData.GetProgress(selectedCampaing.InternalName))
                {
                    playerData.Points += selectedMission.PointsGain;
                    playerData.SetProgress(selectedCampaing.InternalName, Progress);
                }
                Mission oldMission = selectedMission;
                if (Index >= Manager.Menues["Mission"].Controls.Count)
                {
                    //Switch episodes
                    HexControl hexControl = (HexControl)Manager.Menues["Strategic"].Controls.First(c => c is HexControl);
                    foreach (int cell in selectedEpisode.Cells)
                    {
                        hexControl[cell].Color = new Color(53, 234, 28) * 0.7f;
                    }
                    hexControl[selectedEpisode.Position].Color = new Color(53, 234, 28) * 0.7f;
                    Index = selectedCampaing.Episodes.IndexOf(selectedEpisode) + 1;

                    if (Index >= selectedCampaing.Episodes.Count)
                    {
                        textManager.Text = selectedMission.Name + "\n\n\n\n\n" + selectedMission.Description;
                        textManager.Parse();

                        //Last episode
                        Manager.ClearHistory();
                        Manager.InjectMenu(Manager.Menues["Main"]);
                        if (!string.IsNullOrWhiteSpace(oldMission.Popup))
                        {
                            PopupTextManager.Text = oldMission.Popup;
                            PopupTextManager.Parse();
                            ShowEpilogueAfter = true;
                            PopupMB.Show(true);

                        }
                        else
                        {
                            (Manager.Menues["Epilogue"] as EpilogueMenu).Prepare(selectedCampaing);
                            Manager.SetMenu("Epilogue");
                        }
                    }
                    else
                    {

                        selectedEpisode = selectedCampaing.Episodes[Index];
                        hexControl[selectedEpisode.Position].Color = Color.Yellow * 0.5f;
                        EpisodeProgressCounter = 0;
                        foreach (Episode ep in selectedCampaing.Episodes)
                        {
                            if (ep != selectedEpisode)
                                EpisodeProgressCounter += ep.Missions.Count;
                            else
                                break;
                        }
                        //Trigget menu change event to rebuild the mission
                        //Manager_OnBeginMenuChange(this, new MenuChangeEventArgs() { Menu = Manager.Menues["Mission"] });
                        if (!string.IsNullOrWhiteSpace(oldMission.Popup))
                        {
                            ShowStrategicAfter = true;
                            textManager.Text = selectedMission.Name + "\n\n\n\n\n" + selectedMission.Description;
                            textManager.Parse();
                            PopupTextManager.Text = oldMission.Popup;
                            PopupTextManager.Parse();
                            PopupMB.Show(true);
                        }
                        else
                        {
                            Manager.SetMenu("Strategic");
                            Manager.ClearHistory();
                            Manager.InjectMenu(Manager.Menues["Main"]);
                            Manager.InjectMenu(Manager.Menues["Campaing"]);
                            Manager.InjectMenu(Manager.Menues["Base"]);
                        }
                    }
                }
                else
                {
                    LastControl = Manager.Menues["Mission"].Controls[Index];
                    LastControl.Color = Color.Gray;
                    LastControl.Enabled = true;
                    if (!string.IsNullOrWhiteSpace(selectedMission.Popup))
                    {
                        PopupTextManager.Text = selectedMission.Popup;
                        PopupTextManager.Parse();
                        PopupMB.Show(true);
                    }
                    selectedMission = LastControl.Tag as Mission;

                    textManager.Text = selectedMission.Name + "\n\n\n\n\n" + selectedMission.Description;
                    textManager.Parse();
                }
            }
            else
            {
                textManager.Text = selectedMission.Name + "\n\n\n\n\n" + selectedMission.Description;
                textManager.Parse();
                PopupTextManager.Text = LocalizationData.GG;
                PopupTextManager.Parse();
                PopupMB.Show(true);
            }
            playerData.Save();
            GameManager = null;
        }
Exemple #4
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();
        }
Exemple #5
0
 void Exit_OnClick(object sender, EventArgs e)
 {
     Manager.Enabled = true;
     MainMenuContract.Enabled = true;
     SinglePlayerContract.Enabled = false;
     GameScript.Dispose();
     GameScript = null;
     GameState = GameState.Menu;
     LevelContentManager.Unload();
     LevelContentManager.Dispose();
     PauseManager.Enabled = false;
     //textSettings.Scale = 1;
     //textSettings.Origin = Vector2.Zero;
     //textSettings.Width = 200;
     //textSettings.Offset = new Vector2(545, 50);
     //textSettings.Depth = 0.49f;
     textManager.Settings.Width = 200;
     textManager.Settings.Offset = new Vector2(545, 50);
     textManager.Text = selectedMission.Name + "\n\n\n\n\n" + selectedMission.Description;
     textManager.Parse();
     GameManager = null;
     GameActions = 0;
     GameTimeSpent = TimeSpan.Zero;
 }
Exemple #6
0
 void EnterEditorMode(object sender, EventArgs e)
 {
     //Remote Begin
     remoteManager = new RemoteManager();
     remoteManager.Connect(new System.Net.IPEndPoint(System.Net.IPAddress.Parse("192.168.1.109"), 29092));
     GameState = GameState.Editor;
     Manager.Enabled = false;
     MainMenuContract.Enabled = false;
     SetupCameraSmall();
     Width = 800;
     Height = 480;
     GameManager = new GameManager();
     LevelContentManager = new ContentManager(this, "Content");
     LevelContentManager.Load<Texture2D>("Graphics/Planets/Large/Populated/1");
 }
Exemple #7
0
        private void GenerateActionPlan(GameManager gm)
        {
            int Difficulty=(int)GameBase.playerData.Difficulty;
            //Santize the data
            for (int i = 0; i < Actions.Count; i++)
            {
                if (Actions[i].ActionType == AIActionType.Deffend && Actions[i].Target.Owner != PlayerType.Player2)
                {
                    Actions.RemoveAt(i);
                    i--;
                }
                else if (Actions[i].ActionType == AIActionType.Attack && Actions[i].Target.Owner == PlayerType.Player2)
                {
                    Actions.RemoveAt(i);
                    i--;
                }
            }

            //Need to defend?
            foreach (Planet MyPlanet in gm.State.AIPlanets)
            {
                //Is this planet under attack already?
                bool UnderAttack = Actions.Any(action => action.Target == MyPlanet&&action.ActionType==AIActionType.Deffend);
                if (UnderAttack)
                    continue;//Nothing to do here

                IEnumerable<Fleet> AttackingFleets = (from fleet in gm.State.Fleets where fleet.Destination == MyPlanet && fleet.Owner == PlayerType.Player1 select fleet);
                if (UnderAttack && AttackingFleets.Count() == 0)
                    Actions.Remove(Actions.First(a => a.Target == MyPlanet));

                //Can we deal with it?
                int NetForce = AttackingFleets.Sum(f=>f.Count);

                if (NetForce > MyPlanet.Forces)
                {
                    //Defend
                    AIAction action = new AIAction();
                    action.ActionType = AIActionType.Deffend;
                    action.Target = MyPlanet;
                    Actions.Add(action);
                }
            }

            //Lets see if we want to attack something
            Dictionary<Planet, float> MeanDistance = new Dictionary<Planet, float>();
            foreach (Planet planet in gm.State.Planets)
            {
                if (planet.Owner != PlayerType.Player2)
                {
                    float Distance = 0;
                    int Count = 0;
                    foreach (Planet myplanet in gm.State.GetMyPlanets(PlayerType.Player2))
                    {
                        Distance += Vector2.Distance(planet.Position, myplanet.Position);
                        Count++;
                    }
                    Distance /= Count;
                    MeanDistance.Add(planet, Distance);
                }
            }
            IEnumerable<Planet> AttackablePlanets = (from planet in gm.State.Planets where planet.Owner != PlayerType.Player2 orderby (10 * planet.Forces - (10f * planet.Growth*planet.GrowthReset) + 5*MeanDistance[planet] + Difficulty==1?rnd.Next(0,2000)-1000:0) ascending select planet);
            Planet first = AttackablePlanets.FirstOrDefault();
            if (first == null)
                return;
            if (Difficulty<=2)
            {
                if (!Actions.Any(a => a.Target == first))
                {
                    AIAction action = new AIAction();
                    action.ActionType = AIActionType.Attack;
                    action.Target = first;
                    Actions.Add(action);
                }
            }
            else
            {
                foreach (Planet p in AttackablePlanets)
                {
                    if (!Actions.Any(a => a.Target == p))
                    {
                        AIAction action = new AIAction();
                        action.ActionType = AIActionType.Attack;
                        action.Target = p;
                        Actions.Add(action);
                    }
                }
            }
        }
Exemple #8
0
        private void ImplementActionPlan(GameManager gm)
        {
            int Difficulty = (int)GameBase.playerData.Difficulty;
            IEnumerable<AIAction> DefenseActions = from action in Actions where action.ActionType == AIActionType.Deffend select action;
            IEnumerable<AIAction> AttackActions = from action in Actions where action.ActionType == AIActionType.Attack select action;

            //Process defense first
            foreach (AIAction action in DefenseActions)
            {
                IEnumerable<Fleet> AttackingFleets = (from fleet in gm.State.Fleets where fleet.Destination == action.Target && fleet.Owner == PlayerType.Player1 select fleet);
                IEnumerable<Fleet> DefendingFleets = (from fleet in gm.State.Fleets where fleet.Destination == action.Target && fleet.Owner == PlayerType.Player2 select fleet);

                int NetAttackForce = AttackingFleets.Sum(f => f.Count);
                NetAttackForce *= (int)((1 + GameBase.playerData.Research["Attack"] * 0.05f));
                int NetDefenseForce = DefendingFleets.Sum(f => f.Count)+action.Target.Forces;

                if (NetAttackForce > NetDefenseForce)
                {
                    if (Difficulty <=1)
                        break;
                    //Get some more troops
                    IEnumerable<Planet> supportPlanets = (from planet in gm.State.AIPlanets where planet != action.Target orderby planet.Forces ascending select planet);
                    int SupportForces=0;
                    List<Planet> sp = new List<Planet>();
                    foreach (Planet p in supportPlanets)
                    {
                        if (SupportForces + NetDefenseForce > NetAttackForce)
                            break;

                        sp.Add(p);
                        SupportForces += p.Forces / 2;
                    }
                    if (SupportForces + NetDefenseForce > NetAttackForce)
                    {
                        //We can save the planet
                        foreach (Planet planet in sp)
                        {
                            SinceLastCommand = TimeSpan.Zero;
                            gm.SendFleet(planet.Forces / 2, planet, action.Target);
                        }
                    }
                    else
                    {
                        //We can't, well shit
                    }
                }
            }

            foreach (AIAction action in AttackActions)
            {
                IEnumerable<Fleet> AttackingFleets = (from fleet in gm.State.Fleets where fleet.Destination == action.Target && fleet.Owner == PlayerType.Player2 select fleet);
                IEnumerable<Fleet> DefendingFleets = (from fleet in gm.State.Fleets where fleet.Destination == action.Target && fleet.Owner == PlayerType.Player1 select fleet);
                float MaxDistance = gm.State.AIPlanets.Max(p => Vector2.Distance(p.Position, action.Target.Position));
                int NetAttackForce = AttackingFleets.Sum(f => f.Count);
                int NetDefenseForce = DefendingFleets.Sum(f => f.Count) + action.Target.Forces;
                NetDefenseForce*=(int)((1+GameBase.playerData.Research["Defense"]*0.05f));
                if (action.Target.Owner != PlayerType.Neutral)
                {
                    NetDefenseForce+=(int)(action.Target.Growth * (MaxDistance / 1.15f / action.Target.GrowthReset));
                }
                if (NetDefenseForce > NetAttackForce)
                {
                    //Send more troops
                    IEnumerable<Planet> supportPlanets = (from planet in gm.State.AIPlanets where !gm.State.Fleets.Any(f=>f.Owner==PlayerType.Player1&&f.Destination==planet) orderby planet.Forces ascending select planet);
                    Planet firstAttackPlanet = supportPlanets.LastOrDefault(p => (p.Forces / 2 + NetAttackForce) > NetDefenseForce); //Do we have a planet that can attack by itself?
                    if (firstAttackPlanet != null)
                    {
                        SinceLastCommand = TimeSpan.Zero;
                        gm.SendFleet(firstAttackPlanet.Forces / 2, firstAttackPlanet, action.Target);
                    }
                    else if(Difficulty>0)
                    {
                        int SupportForces = 0;
                        List<Planet> sp = new List<Planet>();
                        foreach (Planet p in supportPlanets)
                        {
                            if (SupportForces + NetAttackForce > NetDefenseForce)
                                break;

                            sp.Add(p);
                            SupportForces += p.Forces / 2;
                        }
                        if (SupportForces + NetAttackForce > NetDefenseForce)
                        {
                            //We can capture the planet
                            foreach (Planet planet in sp)
                            {
                                SinceLastCommand = TimeSpan.Zero;
                                gm.SendFleet(planet.Forces / 2, planet, action.Target);
                            }
                        }
                        else
                        {
                            //We can't, well shit
                        }
                    }
                }
            }
        }