コード例 #1
0
        /// <summary>
        /// Called when a new fromBuilding should be created. Creates a fromBuilding of a given type at the
        /// given point from the given sourceBuilding. Returns false if it failed.
        /// </summary>
        /// <param name="point"></param>
        /// <param name="baseBuilding"></param>
        /// <param name="buildingType"></param>
        /// <returns></returns>
        private bool IssueBuildOrder(Vector2 point, Building sourceBuilding, Globals.BuildingTypes buildingType)
        {
            bool created = BuildingController.AddBuilding(buildingType, sourceBuilding, point, m_view.world, this);

            if (created)
            {
                m_view.BuildingAddedAt(point);
            }

            return(created);
        }
コード例 #2
0
        public void Run()
        {
            backgroundSound.Play();

            while (!finished)
            {
                logger.Debug("Victor turner is turning the page!");
                foreach (Player player in players)
                {
                    if (player is AIPlayer)
                    {
                        logger.Debug(player.color + " is a AIPlayer!");
                        ((AIPlayer)player).MakeMove();
                    }
                    else if (player is Player)
                    {
                        logger.Debug(player.color + " is human!");
                        //This only makes the grid of GUIRegions and scroll zones, remove later.
                        humanControl.Run();
                    }
                    else
                    {
                        logger.Fatal("Could not identify " + player.color + " player!");
                    }
                    if (CheckIfLostOrWon(players))
                    {
                        finished = true;
                        EndGame(players[0]);
                        break;
                    }
                }
                if (finished)
                {
                    break;
                }
                logger.Info("Weighting graphs!");
                foreach (Player player in players)
                {
                    player.unitAcc.ProduceUnits();
                }

                graphControl.CalculateWeights();

                // This is where we start "animating" all movement
                // FIXME: This ain't okay, hombrey
                // Let the units move!
                logger.Info("Moving units!");

                for (int u = 0; u < 5; u++)
                {
                    foreach (Player p in players)
                    {
                        BuildingController.AggressiveBuildingAct(p);
                    }

                    for (int i = 0; i < 100; i++)
                    {
                        UnitController.Update(world.units, 1, world.GetMap());
                        System.Threading.Thread.Sleep(10);
                    }
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// Loads the Building menu from a selection.
        /// Must have building on tile.
        /// </summary>
        /// <param name="theSelection"></param>
        private void BuildingMenu()
        {
            World.Map map      = theWorld.GetMap();
            Building  building = selectedTile.GetBuilding();

            if (building == null || building.owner != playerInControll)
            {
                return;
            }
            int toHeal = Math.Min(building.maxHealth - building.currentHealth, building.units.Count());

            MenuIcon setWeight    = new MenuIcon(Language.Instance.GetString("SetWeight"));
            MenuIcon buildCell    = new MenuIcon(Language.Instance.GetString("BuildCell"));
            MenuIcon removeCell   = new MenuIcon(Language.Instance.GetString("RemoveCell"));
            MenuIcon upgradeUnits = new MenuIcon(Language.Instance.GetString("UpgradeUnits") + " (" + playerInControll.unitAcc.GetUpgradeCost() + ")");
            MenuIcon moveUnits    = new MenuIcon(Language.Instance.GetString("MoveUnits"));
            MenuIcon repairCell   = new MenuIcon(Language.Instance.GetString("RepairCell") + " (" + toHeal + ")");
            MenuIcon setAggro     = new MenuIcon(Language.Instance.GetString("SetAggro"));
            MenuIcon Cancel       = new MenuIcon(Language.Instance.GetString("Cancel"), Recellection.textureMap.GetTexture(Globals.TextureTypes.No));

            List <MenuIcon> menuIcons = new List <MenuIcon>();

            menuIcons.Add(setWeight);
            menuIcons.Add(buildCell);
            menuIcons.Add(removeCell);
            menuIcons.Add(upgradeUnits);
            menuIcons.Add(moveUnits);
            menuIcons.Add(repairCell);
            menuIcons.Add(setAggro);
            menuIcons.Add(Cancel);

            Menu buildingMenu = new Menu(Globals.MenuLayout.NineMatrix, menuIcons, Language.Instance.GetString("BuildingMenu"), Color.Black);

            MenuController.LoadMenu(buildingMenu);
            Recellection.CurrentState = MenuView.Instance;
            MenuIcon choosenMenu = MenuController.GetInput();

            Recellection.CurrentState = WorldView.Instance;
            MenuController.UnloadMenu();

            if (choosenMenu.Equals(setWeight))
            {
                GraphController.Instance.SetWeight(building);
            }
            else if (choosenMenu.Equals(buildCell))
            {
                tobii.SetFeedbackColor(Color.DarkGreen);
                Selection destsel;
                do
                {
                    SetConstructionLines(BuildingController.GetValidBuildingInterval(selectedTile.position, theWorld));
                    destsel = retrieveSelection();
                    RemoveconstructionTileLines(BuildingController.GetValidBuildingInterval(selectedTile.position, theWorld));
                }while (destsel.state != State.TILE);

                tobii.SetFeedbackColor(Color.White);

                SelectTile(map.GetTile(destsel.absPoint));

                //TODO Add a check to see if the tile is a correct one. The diffrence between the selected tiles coordinates and the source building shall not exceed 3.
                if (selectedTile.GetBuilding() == null)
                {
                    try
                    {
                        BuildingController.ConstructBuilding(playerInControll, selectedTile, building, theWorld);
                        tobii.SetFeedbackColor(Color.White);
                    }
                    catch (BuildingController.BuildingOutOfRangeException)
                    {
                        logger.Debug("Caught BuildingOutOfRangeExcpetion");
                    }
                }
                else
                {
                    //SoundsController.playSound("Denied");
                    tobii.SetFeedbackColor(Color.White);
                    return;
                }
            }
            else if (choosenMenu.Equals(removeCell))
            {
                BuildingController.RemoveBuilding(building);
            }
            else if (choosenMenu.Equals(upgradeUnits))
            {
                upgradeMenu();
            }
            else if (choosenMenu.Equals(moveUnits))
            {
                tobii.SetFeedbackColor(Color.Red);

                Selection destsel = retrieveSelection();
                if (destsel.state == State.BUILDING || destsel.state == State.TILE)
                {
                    Tile selTile = map.GetTile(destsel.absPoint);
                    UnitController.MoveUnits(playerInControll, selectedTile, selTile, building.GetUnits().Count);
                }

                tobii.SetFeedbackColor(Color.White);
            }
            else if (choosenMenu.Equals(repairCell))
            {
                playerInControll.unitAcc.DestroyUnits(building.units, toHeal);
                building.Repair(toHeal);
            }
            else if (choosenMenu.Equals(setAggro))
            {
                building.IsAggressive = !building.IsAggressive;
                building.UpdateAggressiveness(null, new Event <IEnumerable <Unit> >(building.GetUnits(), EventType.ADD));
            }
            else if (choosenMenu.Equals(Cancel))
            {
                return;
            }
            else
            {
                return;
            }
        }
コード例 #4
0
        private void GameMenu()
        {
            MenuIcon endTurn = new MenuIcon(Language.Instance.GetString("EndTurn"));
            MenuIcon endGame = new MenuIcon(Language.Instance.GetString("EndGame"));
            MenuIcon cancel  = new MenuIcon(Language.Instance.GetString("Cancel"), Recellection.textureMap.GetTexture(Globals.TextureTypes.No));

            List <MenuIcon> options = new List <MenuIcon>(4);

            options.Add(endTurn);
            options.Add(endGame);
            options.Add(cancel);

            Menu menu = new Menu(Globals.MenuLayout.FourMatrix, options, "");

            MenuController.LoadMenu(menu);

            bool done = false;

            while (!done)
            {
                Recellection.CurrentState = MenuView.Instance;
                MenuIcon input = MenuController.GetInput();
                if (input == endTurn)
                {
                    finished = true;
                    break;
                }
                else if (input == endGame)
                {
                    List <MenuIcon> promptOptions = new List <MenuIcon>(2);
                    MenuIcon        yes           = new MenuIcon(Language.Instance.GetString("Yes"), Recellection.textureMap.GetTexture(Globals.TextureTypes.Yes));
                    MenuIcon        no            = new MenuIcon(Language.Instance.GetString("No"), Recellection.textureMap.GetTexture(Globals.TextureTypes.No));
                    promptOptions.Add(yes);
                    promptOptions.Add(no);
                    MenuController.LoadMenu(new Menu(Globals.MenuLayout.Prompt, promptOptions, Language.Instance.GetString("AreYouSureYouWantToEndTheGame")));
                    MenuIcon inp = MenuController.GetInput();
                    MenuController.UnloadMenu();

                    if (inp == yes)
                    {
                        // This should make the player lose :D
                        List <Building> buildingsToRemove = new List <Building>();
                        foreach (Graph g in playerInControll.GetGraphs())
                        {
                            foreach (Building b in g.GetBuildings())
                            {
                                buildingsToRemove.Add(b);
                            }
                        }
                        foreach (Building b in buildingsToRemove)
                        {
                            BuildingController.RemoveBuilding(b);
                        }
                        finished = true;
                        break;
                    }
                }
                else if (input == cancel)
                {
                    break;
                }
            }
            Recellection.CurrentState = WorldView.Instance;
            MenuController.UnloadMenu();
        }
コード例 #5
0
        /// <summary>
        /// The main method. When called it causes the AIPlayer to reevaluate
        /// its situation and make appropriate changes.
        /// </summary>
        public void MakeMove()
        {
            log.Info("AI Making a Move.");

            m_view.LookAtScreen(); //Have the AI View update its local variables
            if (m_view.myBuildings.Count == 0)
            {
                return;
            }
            resourceThreshold = GetResourceThreshold();

            int resourceLocations = m_view.GetResourceLocations().Count;

            if (resourceLocations < resourceThreshold)
            {//While we have secured less resource points than we should have, get some!
                log.Info("Not enough resource points. Need " + resourceThreshold + ", have " + resourceLocations);
                SecureNextResourceHotSpot();
            }

            if (resourceLocations < resourceCriticalThreshold)
            {//If we have not secured basic income, dont worry about anything else.
                log.Info("Not enough resource points so nothing more to do this turn.");
                log.Info("//Ending turn");
                return;
            }


            if (GetGraphs()[0].baseBuilding == null)
            { //Our base building has been destroyed! Create a new one from where we can afford it.
                Building relay = Util.FindBuildingWithUnitCount((int)unitAcc.CalculateBuildingCostInflation(Globals.BuildingTypes.Base), m_view.myBuildings);
                if (relay == null)
                {
                    return;
                }
                IssueBuildOrder(Util.GetRandomBuildPointFrom(Util.CreateMatrixFromInterval(BuildingController.GetValidBuildingInterval(relay.GetPosition(), m_view.world)), m_view.world), relay, Globals.BuildingTypes.Base);
            }

            //Reset all the building weights.
            SetWeights(m_view.myBuildings, 0);


            //If we are falling behind on the upgrades: catch up.
            if (m_view.opponents[0].PowerLevel > this.PowerLevel)
            {
                log.Info("Attempting to upgrading units.");
                UpgradeUnits();
            }

            if (ShouldAttack())
            {
                AttackWeakestFrontPoint();
            }


            List <Building> enemyFront = new List <Building>();
            List <Building> front      = GetFrontLine(enemyFront);

            log.Info("Weighing the frontline");
            WeighFrontLine(front, enemyFront);
            SetCriticalWeights();
            log.Info("//Ending turn");
        }