Example #1
0
        private void StealTechnology(object sender, EventArgs args)
        {
            IAdvance advance = _diplomat.GetAdvanceToSteal(_enemyCity.Player);

            if (advance == null)
            {
                GameTask.Insert(Message.General($"No new technology found"));
            }
            else
            {
                GameTask task = new Tasks.GetAdvance(_diplomat.Player, advance);

                task.Done += (s1, a1) =>
                {
                    Game.DisbandUnit(_diplomat);
                    if (_diplomat.Player == Human || _enemyCity.Player == Human)
                    {
                        GameTask.Insert(Message.Spy("Spies report:", $"{_diplomat.Player.TribeName} steal", $"{advance.Name}"));
                    }
                };

                GameTask.Enqueue(task);
            }

            Cancel();
        }
Example #2
0
        private void CitySizeSet_Accept(object sender, EventArgs args)
        {
            Value = (sender as Input).Text;

            byte citySize;

            if (!byte.TryParse(Value, out citySize) || citySize < 1 || citySize > 99)
            {
                GameTask.Enqueue(Message.Error("-- DEBUG: Set City Size --", $"The value {Value} is invalid or out of range.", "Please enter a value between 1 and 99."));
            }
            else
            {
                _selectedCity.Size = citySize;
                GameTask.Enqueue(Message.General($"{_selectedCity.Name} size set to {citySize}."));
            }

            if (Accept != null)
            {
                Accept(this, null);
            }
            if (sender is Input)
            {
                ((Input)sender)?.Close();
            }
            Destroy();
        }
Example #3
0
 private MenuItem <int> MenuBuildIrrigation() => MenuItem <int>
 .Create((Map[X, Y] is Forest)? "Change to Plains" :
         ((Map[X, Y] is Jungle) || (Map[X, Y] is Swamp))? "Change to Grassland" :
         "Build Irrigation")
 .SetShortcut("i")
 .SetEnabled(Map[X, Y].AllowIrrigation() || Map[X, Y].AllowChangeTerrain())
 .OnSelect((s, a) => GameTask.Enqueue(Orders.BuildIrrigation(this)));
Example #4
0
        private void PlayerScience_Accept(object sender, EventArgs args)
        {
            Value = (sender as Input).Text;

            short playerScience;

            if (!short.TryParse(Value, out playerScience) || playerScience < 0 || playerScience > 30000)
            {
                GameTask.Enqueue(Message.Error("-- DEBUG: Set Player Science --", $"The value {Value} is invalid or out of range.", "Please enter a value between 0 and", "30000."));
            }
            else
            {
                if (playerScience > _selectedPlayer.ScienceCost)
                {
                    playerScience = _selectedPlayer.ScienceCost;
                }
                _selectedPlayer.Science = playerScience;
                GameTask.Enqueue(Message.General($"{_selectedPlayer.TribeName} science set to {playerScience}~."));
            }

            if (Accept != null)
            {
                Accept(this, null);
            }
            if (sender is Input)
            {
                ((Input)sender)?.Close();
            }
            Destroy();
        }
Example #5
0
        protected override bool Confront(int relX, int relY)
        {
            ITile moveTarget = Map[X, Y][relX, relY];
            City  city       = moveTarget.City;

            if (city == null || city == Home || (city.Owner == Owner && Home != null && moveTarget.DistanceTo(Home) < 10))
            {
                Movement       = new MoveUnit(relX, relY);
                Movement.Done += MoveEnd;
                GameTask.Insert(Movement);
                return(true);
            }

            if (city.Owner != Owner)
            {
                EstablishTradeRoute(moveTarget.City);
                return(true);
            }

            if (Game.Human == Owner)
            {
                GameTask.Enqueue(Show.CaravanChoice(this, city));
            }

            return(true);
        }
Example #6
0
        private void GameYear_Accept(object sender, EventArgs args)
        {
            Value = (sender as Input).Text;

            int gameYear;

            if (!int.TryParse(Value, out gameYear) || gameYear < -4000 || gameYear > 6000)
            {
                GameTask.Enqueue(Message.Error("-- DEBUG: Set Game Year --", $"The value {Value} is invalid or out of range.", "Please enter a value between -4000 and", "6000."));
            }
            else
            {
                Game.GameTurn = Common.YearToTurn(gameYear);
                GameTask.Enqueue(Message.General($"Game year set to {Game.GameYear}."));
            }

            if (Accept != null)
            {
                Accept(this, null);
            }
            if (sender is Input)
            {
                ((Input)sender)?.Close();
            }
            Destroy();
        }
Example #7
0
        public override void Run()
        {
            _player.AddAdvance(_advance);

            if (_player.CurrentResearch == _advance)
            {
                _player.CurrentResearch = null;
                _player.Science         = 0; // fire-eggs 20170729 if player acquires advance from city/steal/hut, do NOT roll-over existing lightbulbs
            }

            if (!_human)
            {
                EndTask();
                return;
            }

            if (_player.CurrentResearch == null)
            {
                GameTask.Enqueue(new TechSelect(_player));
            }

            Screens.Civilopedia civilopedia = new Screens.Civilopedia(_advance, discovered: true);
            civilopedia.Closed += CivilopediaClosed;
            Common.AddScreen(civilopedia);
        }
Example #8
0
        private void HandleFuel()
        {
            if (Map[X, Y].Units.Any(u => u.Name == "Carrier"))
            {
                if (CarrierIsLandable())
                {
                    MovesLeft = 0;
                    FuelLeft  = TotalFuel;                              // Refuel
                    return;
                }
            }

            if (Map[X, Y].City != null)
            {
                MovesLeft = 0;
                FuelLeft  = TotalFuel;                                  // Refuel
                return;
            }


            if (MovesLeft > 0 || FuelLeft > 0)
            {
                return;
            }

            // Air unit is out of fuel
            Game.DisbandUnit(this);
            GameTask.Enqueue(Message.Error("-- Civilization Note --", TextFile.Instance.GetGameText("ERROR/FUEL")));
        }
Example #9
0
        internal override bool Confront(int relX, int relY)
        {
            ITile moveTarget = Map[X, Y][relX, relY];
            City  city       = moveTarget.City;

            // fire-eggs Caravan can build wonder even in home city
            if (city != null && city.Owner == Owner && Game.Human == Owner)
            {
                // TODO fire-eggs this seems like bad design: how to determine whether to show a menu, without activating the menu?
                if (city.IsBuildingWonder || CaravanChoice.AllowEstablishTradeRoute(this, city))
                {
                    GameTask.Enqueue(Show.CaravanChoice(this, city));
                }
                else
                {
                    MovementTo(relX, relY);
                }
                return(true);
            }

            if (city == null || city == Home || (city.Owner == Owner && Home != null && moveTarget.DistanceTo(Home) < 10))
            {
                MovementTo(relX, relY);
                return(true);
            }

            if (city.Owner != Owner)
            {
                EstablishTradeRoute(moveTarget.City);
                return(true);
            }

            return(true);
        }
Example #10
0
        private void PlayerGold_Accept(object sender, EventArgs args)
        {
            Value = (sender as Input).Text;

            short playerGold;

            if (!short.TryParse(Value, out playerGold) || playerGold < 0 || playerGold > 30000)
            {
                GameTask.Enqueue(Message.Error("-- DEBUG: Set Player Gold --", $"The value {Value} is invalid or out of range.", "Please enter a value between 0 and", "30000."));
            }
            else
            {
                _selectedPlayer.Gold = playerGold;
                GameTask.Enqueue(Message.General($"{_selectedPlayer.TribeName} gold set to {playerGold}$."));
            }

            if (Accept != null)
            {
                Accept(this, null);
            }
            if (sender is Input)
            {
                ((Input)sender)?.Close();
            }
            Destroy();
        }
Example #11
0
        public override bool KeyDown(KeyboardEventArgs args)
        {
            if (Game.CurrentPlayer != Human)
            {
                // Ignore all keypresses if the current player is not human
                return(false);
            }

            switch (args.KeyChar)
            {
            case 'G':
                GameTask.Enqueue(Show.Goto);
                return(true);

            case 'T':
                GameTask.Enqueue(Show.Terrain);
                return(true);
            }

            if (Game.ActiveUnit != null)
            {
                return(KeyDownActiveUnit(args));
            }

            switch (args.Key)
            {
            case Key.Space:
            case Key.Enter:
                GameTask.Enqueue(Turn.End());
                return(true);
            }
            return(false);
        }
Example #12
0
        public override bool MouseDown(ScreenEventArgs args)
        {
            if (args.Y <= 50)
            {
                if (args.X < 1 || args.Y < 1 || args.X > 79 || args.Y > 49)
                {
                    return(true);
                }

                int xx = (args.X - 1) + GamePlay.X - 30;
                int yy = (args.Y - 1) + GamePlay.Y - 18;

                GamePlay.CenterOnPoint(xx, yy);
            }
            if (args.Y > 50 && args.Y < 62)
            {
                Log("Sidebar: Palace View");
                Common.AddScreen(new PalaceView());
            }
            else if (args.Y >= 62)
            {
                if (Game.CurrentPlayer == Human && Game.ActiveUnit == null)
                {
                    GameTask.Enqueue(Turn.End());
                }
            }
            return(true);
        }
Example #13
0
 private void MenuRevolution(object sender, EventArgs args)
 {
     Human.Revolt();
     GameTask.Enqueue(Message.Newspaper(null,
                                        $"The {Human.Civilization.NamePlural} are",
                                        "revolting! Citizens", "demand new govt."));
     Cancel();
 }
Example #14
0
        public CauseDisaster() : base(MouseCursor.Pointer)
        {
            if (_cities.Length == 0)
            {
                GameTask.Enqueue(Message.General($"There are no cities yet."));
                return;
            }

            CitiesMenu();
        }
Example #15
0
        public SetCitySize()
        {
            Cursor = MouseCursor.Pointer;

            if (_cities.Length == 0)
            {
                GameTask.Enqueue(Message.General($"There are no cities yet."));
                return;
            }

            CitiesMenu();
        }
Example #16
0
 private GameMenu.Item MenuBuildFortress()
 {
     GameMenu.Item item = new GameMenu.Item("Build fortress", "f");
     if (!Game.CurrentPlayer.HasAdvance <Construction>())
     {
         item.Enabled = false;
     }
     else
     {
         item.Selected += (s, a) => GameTask.Enqueue(Orders.BuildFortress(this));
     }
     return(item);
 }
Example #17
0
 private GameMenu.Item MenuBuildMines()
 {
     GameMenu.Item item;
     if ((Map[X, Y] is Jungle) || (Map[X, Y] is Grassland) || (Map[X, Y] is Plains) || (Map[X, Y] is Swamp))
     {
         item = new GameMenu.Item("Change to Forest", "m");
     }
     else
     {
         item = new GameMenu.Item("Build Mines", "m");
     }
     item.Selected += (s, a) => GameTask.Enqueue(Orders.BuildMines(this));
     return(item);
 }
Example #18
0
 private GameMenu.Item MenuFoundCity()
 {
     GameMenu.Item item;
     if (Map[X, Y].City == null)
     {
         item = new GameMenu.Item("Found New City", "b");
     }
     else
     {
         item = new GameMenu.Item("Add to City", "b");
     }
     item.Selected += (s, a) => GameTask.Enqueue(Orders.FoundCity(this));
     return(item);
 }
Example #19
0
        public bool BuildIrrigation()
        {
            ITile tile = Map[X, Y];

            if (tile.Irrigation)
            {
                // Tile already irrigated, ignore
                return(false);
            }

            if ((tile is Forest) || (tile is Jungle) || (tile is Swamp))
            {
                BuildingIrrigation = 4;
                MovesLeft          = 0;
                PartMoves          = 0;
                return(true);
            }
            else if ((tile.GetBorderTiles().Any(t => (t.X == X || t.Y == Y) && (t.City == null) && (t.IsOcean || t.Irrigation || (t is River)))) || (tile is River))
            {
                if (!tile.IsOcean && !(tile.Irrigation) && ((tile is Desert) || (tile is Grassland) || (tile is Hills) || (tile is Plains) || (tile is River)))
                {
                    BuildingIrrigation = 3;
                    MovesLeft          = 0;
                    PartMoves          = 0;
                    return(true);
                }
                if (Human == Owner)
                {
                    GameTask.Enqueue(Message.Error("-- Civilization Note --", TextFile.Instance.GetGameText("ERROR/NOIRR")));
                }
                return(false);
            }
            else
            {
                if (((tile is Desert) || (tile is Grassland) || (tile is Hills) || (tile is Plains) || (tile is River)) && tile.City == null)
                {
                    if (Human == Owner)
                    {
                        GameTask.Enqueue(Message.Error("-- Civilization Note --", TextFile.Instance.GetGameText("ERROR/NOWATER")));
                    }
                    return(true);
                }
                if (Human == Owner)
                {
                    GameTask.Enqueue(Message.Error("-- Civilization Note --", TextFile.Instance.GetGameText("ERROR/NOIRR")));
                }
            }
            return(false);
        }
Example #20
0
        public override bool KeyDown(KeyboardEventArgs args)
        {
            if (_allowEnterSetup && args.Shift && args.Key == Key.F1)
            {
                GameTask.Enqueue(Show.Screens(typeof(Setup), typeof(Credits)));
                Destroy();
                return(true);
            }

            if (_done && _overlay != null)
            {
                return(_overlay.KeyDown(args));
            }
            return(SkipIntro());
        }
Example #21
0
        public override void Run()
        {
            if (_player.CurrentResearch == null)
            {
                if (_human)
                {
                    GameTask.Enqueue(new TechSelect(_player));
                }
                else
                {
                    AI.ChooseResearch(_player);
                }
                EndTask();
                return;
            }

            if (_player.Science < _player.ScienceCost)
            {
                // Not enough lightbulbs, end the task
                EndTask();
                return;
            }

            _player.Science -= _player.ScienceCost;
            _player.AddAdvance(_player.CurrentResearch);

            if (!_human)
            {
                // This is an AI player, handle everything in the background.
                _player.CurrentResearch = null;
                AI.ChooseResearch(_player);
                EndTask();
                return;
            }

            IScreen discovery;

            if (Settings.Animations)
            {
                discovery = new Discovery(_player.CurrentResearch);
            }
            else
            {
                discovery = new Newspaper(null, new string[] { $"{_player.TribeName} wise men", "discover the secret", $"of {_player.CurrentResearch.Name}!" }, showGovernment: false);
            }
            discovery.Closed += ClosedDiscovery;
            Common.AddScreen(discovery);
        }
Example #22
0
 private GameMenu.Item MenuBuildIrrigation()
 {
     GameMenu.Item item;
     if (Map[X, Y] is Forest)
     {
         item = new GameMenu.Item("Change to Plains", "i");
     }
     else if ((Map[X, Y] is Jungle) || (Map[X, Y] is Swamp))
     {
         item = new GameMenu.Item("Change to Grassland", "i");
     }
     else
     {
         item = new GameMenu.Item("Build Irrigation", "i");
     }
     item.Selected += (s, a) => GameTask.Enqueue(Orders.BuildIrrigation(this));
     return(item);
 }
Example #23
0
        protected override bool Confront(int relX, int relY)
        {
            ITile moveTarget = Map[X, Y][relX, relY];

            if (moveTarget.City != null)
            {
                if (Human == Owner)
                {
                    GameTask.Enqueue(Show.DiplomatCity(moveTarget.City, this));
                    return(true);
                }
                else
                {
                    if (moveTarget.City.Player == Human)
                    {
                        GameTask.Enqueue(Tasks.Show.DiplomatSabotage(moveTarget.City, this));
                    }
                    else
                    {
                        Sabotage(moveTarget.City);
                    }

                    return(true);
                }
            }

            IUnit[] units = moveTarget.Units;

            if (units.Length == 1)
            {
                IUnit unit = units[0];

                if (unit.Owner != Owner && unit is BaseUnitLand)
                {
                    GameTask.Enqueue(Show.DiplomatBribe(unit as BaseUnitLand, this));
                    return(true);
                }
            }

            Movement       = new MoveUnit(relX, relY);
            Movement.Done += MoveEnd;
            GameTask.Insert(Movement);
            return(true);
        }
Example #24
0
        private void MenuBarGame(object sender, EventArgs args)
        {
            bool debugMenu = Settings.DebugMenu;
            int  quitItem  = 8;

            _gameMenu = new GameMenu(_canvas.Palette);
            _gameMenu.Items.Add(new GameMenu.Item("Tax Rate"));
            _gameMenu.Items.Add(new GameMenu.Item("Luxuries Rate"));
            _gameMenu.Items.Add(new GameMenu.Item("FindCity"));
            _gameMenu.Items.Add(new GameMenu.Item("Options"));
            _gameMenu.Items.Add(new GameMenu.Item("Save Game")
            {
                Enabled = (Game.GameTurn > 0)
            });
            _gameMenu.Items.Add(new GameMenu.Item("REVOLUTION!"));
            _gameMenu.Items.Add(new GameMenu.Item(null));
            if (debugMenu)
            {
                quitItem += 2;
                _gameMenu.Items.Add(new GameMenu.Item("Debug Options"));
                _gameMenu.Items.Add(new GameMenu.Item(null));
                _gameMenu.Items[7].Selected += (s, a) => GameTask.Enqueue(Show.Screen <DebugOptions>());
            }
            _gameMenu.Items.Add(new GameMenu.Item("Retire")
            {
                Enabled = false
            });
            _gameMenu.Items.Add(new GameMenu.Item("QUIT to DOS"));

            _gameMenu.Items[0].Selected        += (s, a) => GameTask.Enqueue(Show.TaxRate);
            _gameMenu.Items[1].Selected        += (s, a) => GameTask.Enqueue(Show.LuxuryRate);
            _gameMenu.Items[2].Selected        += (s, a) => GameTask.Enqueue(Show.Search);
            _gameMenu.Items[3].Selected        += (s, a) => GameTask.Enqueue(Show.Screen <GameOptions>());
            _gameMenu.Items[4].Selected        += (s, a) => GameTask.Enqueue(Show.Screen <SaveGame>());
            _gameMenu.Items[5].Selected        += (s, a) => GameTask.Enqueue(Show.Screen <Revolution>());
            _gameMenu.Items[quitItem].Selected += (s, a) => GameTask.Enqueue(Show.Screen <ConfirmQuit>());

            _menuX = 16;
            _menuY = 8;

            _update = true;
        }
Example #25
0
        internal override bool Confront(int relX, int relY)
        {
            ITile moveTarget = Map[X, Y][relX, relY];

            var targetCity = moveTarget.City;

            if (targetCity != null)
            {
                if (Human == Owner)
                {
                    GameTask.Enqueue(Show.DiplomatCity(targetCity, this));
                }
                else if (Human == targetCity.Player)
                {
                    GameTask.Enqueue(Message.Spy("Spies report:", $"{Sabotage(targetCity)}", $"in {targetCity.Name}"));
                }
                else
                {
                    Sabotage(targetCity);
                }

                return(true);
            }

            IUnit[] units = moveTarget.Units;

            if (units.Length == 1)
            {
                IUnit unit = units[0];

                // TODO fire-eggs bribe ocean unit
                if (Human == Owner && unit.Owner != Owner && unit is BaseUnitLand)
                {
                    GameTask.Enqueue(Show.DiplomatBribe(unit as BaseUnitLand, this));
                    return(true);
                }
            }

            MovementTo(relX, relY);
            return(true);
        }
Example #26
0
        public bool BuildIrrigation()
        {
            ITile tile = Map[X, Y];

            if (tile.Irrigation || tile.IsOcean)             // already irrigated or illogical: ignore
            {
                return(false);
            }

            // Changing terrain type
            if (tile.IrrigationChangesTerrain())
            {
                order = Order.Irrigate;
                SkipTurn(tile.IrrigationCost);
                return(true);
            }

            if (!tile.TerrainAllowsIrrigation())
            {
                if (Human == Owner)
                {
                    GameTask.Enqueue(Message.Error("-- Civilization Note --", TextFile.Instance.GetGameText("ERROR/NOIRR")));
                }
                return(false);
            }

            if (tile.AllowIrrigation() || tile.Type == Terrain.River)
            {
                order = Order.Irrigate;
                SkipTurn(tile.IrrigationCost);
                return(true);
            }

            if (Human == Owner)
            {
                GameTask.Enqueue(Message.Error("-- Civilization Note --", TextFile.Instance.GetGameText("ERROR/NOIRR")));
            }
            return(false);
        }
Example #27
0
        private void MenuBarGame(object sender, EventArgs args)
        {
            _gameMenu = new GameMenu("MenuBarGame", Palette.Copy());
            _gameMenu.Items.Add("Tax Rate").OnSelect((s, a) => GameTask.Enqueue(Show.TaxRate));
            _gameMenu.Items.Add("Luxuries Rate").OnSelect((s, a) => GameTask.Enqueue(Show.LuxuryRate));
            _gameMenu.Items.Add("FindCity").OnSelect((s, a) => GameTask.Enqueue(Show.Search));
            _gameMenu.Items.Add("Options").OnSelect((s, a) => GameTask.Enqueue(Show.Screen <GameOptions>()));
            _gameMenu.Items.Add("Save Game").SetEnabled(Game.GameTurn > 0).OnSelect((s, a) => GameTask.Enqueue(Show.Screen <SaveGame>()));
            _gameMenu.Items.Add("REVOLUTION!").OnSelect((s, a) => GameTask.Enqueue(Show.Screen <Revolution>()));
            _gameMenu.Items.Add(null);
            if (Settings.DebugMenu)
            {
                _gameMenu.Items.Add("Debug Options").OnSelect((s, a) => GameTask.Enqueue(Show.Screen <DebugOptions>()));
                _gameMenu.Items.Add(null);
            }
            _gameMenu.Items.Add("Retire").Disable();
            _gameMenu.Items.Add("QUIT to DOS").OnSelect((s, a) => GameTask.Enqueue(Show.Screen <ConfirmQuit>()));

            _menuX = 16;
            _menuY = 8;

            _update = true;
        }
Example #28
0
        public override void Run()
        {
            _player.AddAdvance(_advance);

            if (_player.CurrentResearch == _advance)
            {
                _player.CurrentResearch = null;
            }

            if (!_human)
            {
                EndTask();
                return;
            }

            if (_player.CurrentResearch == null)
            {
                GameTask.Enqueue(new TechSelect(_player));
            }

            Screens.Civilopedia civilopedia = new Screens.Civilopedia(_advance, discovered: true);
            civilopedia.Closed += CivilopediaClosed;
            Common.AddScreen(civilopedia);
        }
Example #29
0
        private void MenuBarWorld(object sender, EventArgs args)
        {
            _gameMenu = new GameMenu("MenuBarWorld", Palette);
            _gameMenu.Items.Add("Wonders of the World (F7)").OnSelect((s, a) => {
                if (Game.BuiltWonders.Length == 0)
                {
                    GameTask.Enqueue(Show.Empty);
                }
                else
                {
                    Common.AddScreen(new WorldWonders());
                }
            });
            _gameMenu.Items.Add("Top 5 Cities (F8)").OnSelect((s, a) => Common.AddScreen(new TopCities()));;
            _gameMenu.Items.Add("Civilization Score (F9)").OnSelect((s, a) => Common.AddScreen(new CivilizationScore()));
            _gameMenu.Items.Add("World Map (F10)").OnSelect((s, a) => Common.AddScreen(new WorldMap()));
            _gameMenu.Items.Add("Demographics").OnSelect((s, a) => Common.AddScreen(new Demographics()));
            _gameMenu.Items.Add("SpaceShips").Disable();

            _menuX = 144;
            _menuY = 8;

            _update = true;
        }
Example #30
0
        protected override void MovementDone(ITile previousTile)
        {
            base.MovementDone(previousTile);

            if (MovesLeft > 0)
            {
                return;
            }

            // Check if the Trireme is at open sea
            if (Tile.GetBorderTiles().Any(t => !(t is Ocean)))
            {
                return;
            }

            // The Trireme unit is surrounded by oceans, there's a 50% chance it will be lost at sea
            if (Common.Random.Next(0, 100) < 50)
            {
                return;
            }

            Game.DisbandUnit(this);
            GameTask.Enqueue(Message.Error("-- Civilization Note --", TextFile.Instance.GetGameText("ERROR/TRIREME")));
        }