/// <summary>TODO</summary>
 protected virtual void OnMouseRightClick(HexEventArgs e)
 {
     if (e == null) throw new ArgumentNullException("e");
     var handler = MouseRightClick;
     if (handler != null) handler(this, e);
 }
        /// <summary>TODO</summary>
        protected override void OnMouseClick(MouseEventArgs e)
        {
            if (e == null) throw new ArgumentNullException("e");

            var eventArgs = new HexEventArgs(GetHexCoords(e.Location), e, ModifierKeys);

            if (e.Button == MouseButtons.Middle) base.OnMouseClick(eventArgs);
            else if (e.Button == MouseButtons.Right) OnMouseRightClick(eventArgs);
            else if (IsAltKeyDown && !IsCtlKeyDown) OnMouseAltClick(eventArgs);
            else if (IsCtlKeyDown) OnMouseCtlClick(eventArgs);
            else OnMouseLeftClick(eventArgs);
        }
 /// <summary>TODO</summary>
 protected virtual void OnHotspotHexChange(HexEventArgs e)
 {
     if (e == null) throw new ArgumentNullException("e");
     var handler = HotspotHexChange;
     if (handler != null) handler(this, e);
 }
Пример #4
0
        private void hexgridPanel1_RightClick(object sender, HexEventArgs e)
        {
            Army a = tm.GetArmy(e.Coords);
            Town t = tm.GetTown(e.Coords);
            Watchtower wt = tm.GetWatchtower(e.Coords);
            Castle c = tm.GetCastle(e.Coords);
            TerrainGridHex hex = (TerrainGridHex)tm.BoardHexes[e.Coords];

            if (isPlayerTurn && newObject == null)
            {
                if (tm.SelectedArmy == null)
                {
                    clickCoords = e.Coords;
                }

                //Move
                if (tm.SelectedArmy != null && tm.InMovement(e.Coords) && tm.SelectedArmy.Coords != e.Coords)
                {
                    //Can't move, own army in the way
                    if (turn.CurrentPlayer.Armies.Contains(a))
                    {
                        MessageBox.Show("Can't move here, other army in the way");
                    }
                    //Siege
                    else if ((c != null && !turn.CurrentPlayer.Castles.Contains(c)) || (t != null && !turn.CurrentPlayer.Towns.Contains(t)))
                    {

                        SiegeForm sf = new SiegeForm();
                        int result = sf.CustomShowDialog();
                        sf.Dispose();

                        HexCoords coords = tm.Path.ElementAt(tm.Path.TotalSteps - 1).StepCoords;

                        switch(result)
                        {
                            case 0:
                                playerDoc.Save(Player.UndoPath);
                                btnUndo.Enabled = true;

                                tm.SelectedArmy.Move(coords, tm);
                                if (c != null) tm.SelectedArmy.Attack(c);
                                if (t != null) tm.SelectedArmy.Attack(t);

                                playerDoc = XDocument.Load(Player.SavePath);
                                break;

                            case 1:
                                playerDoc.Save(Player.UndoPath);
                                btnUndo.Enabled = true;

                                tm.SelectedArmy.Move(coords, tm);
                                if (c != null) tm.SelectedArmy.Siege(c);
                                if (t != null) tm.SelectedArmy.Siege(t);

                                playerDoc = XDocument.Load(Player.SavePath);
                                break;
                        }

                        tm.SelectedArmy = null;
                    }
                    //Attack army
                    else if (a != null && !turn.CurrentPlayer.Armies.Contains(a))
                    {
                        playerDoc.Save(Player.UndoPath);
                        btnUndo.Enabled = true;

                        if (a.Size > 0)
                        {
                            HexCoords coords = tm.Path.ElementAt(tm.Path.TotalSteps - 1).StepCoords;

                            tm.SelectedArmy.Move(coords, tm);
                            tm.SelectedArmy.Attack(a);

                            tm.SelectedArmy = null;

                            playerDoc = XDocument.Load(Player.SavePath);
                        }
                        else
                        {
                            a.Remove();
                            tm.SelectedArmy.Move(e.Coords, tm);
                            tm.SelectedArmy = null;
                        }

                        playerDoc = XDocument.Load(Player.SavePath);
                    }
                    //Move
                    else //(a == null && t == null && c == null && wt == null)
                    {
                        DialogResult result = System.Windows.Forms.DialogResult.Yes;
                        if (tm.SelectedArmy.IsSieging) { result = MessageBox.Show("About to stop sieging. Are you sure?", "Warning", MessageBoxButtons.YesNo); }

                        if (result == System.Windows.Forms.DialogResult.Yes)
                        {
                            playerDoc.Save(Player.UndoPath);
                            btnUndo.Enabled = true;

                            if (tm.SelectedArmy.IsSieging) tm.SelectedArmy.EndSiege();
                            tm.SelectedArmy.Move(e.Coords, tm);
                            tm.SelectedArmy = null;

                            playerDoc = XDocument.Load(Player.SavePath);
                        }
                    }
                }

                //Show menus
                else //if (tm.SelectedArmy == null)
                {
                    if (turn.CurrentPlayer.Armies.Contains(a) && turn.CurrentPlayer.Towns.Contains(t))
                    {
                        cmsArmyTown_BuildBuilding.Enabled = true;
                        cmsArmyTown_IncreaseArmy.Enabled = true;
                        cmsArmyTown_UpgradeTown.Enabled = true;
                        cmsArmyTown_UpgradeObstacles.Enabled = true;
                        cmsArmyTown_UpgradeWalls.Enabled = true;
                        cmsArmyTown_UpgradeTowers.Enabled = true;

                        cmsArmyTown_BuildBuilding.Enabled = false;
                        cmsArmyTown_BuildRoad.Enabled = false;
                        if (t.Level <= 1 || t.IsUnderSiege || t.IsInBattle) cmsArmyTown_IncreaseArmy.Enabled = false;
                        if (t.Level == 20 || t.LevelChanged || !turn.CurrentPlayer.Race.CanPay("UpgradeTown") || t.IsUnderSiege || t.IsInBattle) cmsArmyTown_UpgradeTown.Enabled = false;
                        if (t.Cover == Town.CoverLevels.Last() || !turn.CurrentPlayer.CanUpgradeCover(t) || t.IsUnderSiege || t.IsInBattle) cmsArmyTown_UpgradeObstacles.Enabled = false;
                        if (t.Walls == Town.WallLevels.Last() || !turn.CurrentPlayer.CanUpgradeWalls(t) || t.IsUnderSiege || t.IsInBattle) cmsArmyTown_UpgradeWalls.Enabled = false;
                        if (t.Towers == Town.TowerLevels.Last() || !turn.CurrentPlayer.CanUpgradeTowers(t) || t.IsUnderSiege || t.IsInBattle) cmsArmyTown_UpgradeTowers.Enabled = false;

                        cmsArmyTown.Show(hexgridPanel1, e.X, e.Y);
                    }
                    else if (turn.CurrentPlayer.Armies.Contains(a) && turn.CurrentPlayer.Castles.Contains(c))
                    {
                        cmsArmyCastle_BuildBuilding.Enabled = true;
                        cmsArmyCastle_IncreaseArmy.Enabled = true;
                        cmsArmyCastle_UpgradeCastle.Enabled = true;
                        cmsArmyCastle_UpgradeWalls.Enabled = true;
                        cmsArmyCastle_UpgradeTowers.Enabled = true;
                        cmsArmyCastle_UpgradeGatehouse.Enabled = true;

                        cmsArmyCastle_BuildBuilding.Enabled = false;
                        cmsArmyCastle_BuildRoad.Enabled = false;
                        if (c.Level <= 1 || a != null || c.IsUnderSiege) cmsArmyCastle_IncreaseArmy.Enabled = false;
                        if (c.Level == 20 || c.LevelChanged || !turn.CurrentPlayer.Race.CanPay("UpgradeCastle") || c.IsUnderSiege || c.IsInBattle) cmsArmyCastle_UpgradeCastle.Enabled = false;
                        if (c.Walls == Castle.WallLevels.Last() || !turn.CurrentPlayer.CanUpgradeWalls(c) || c.IsUnderSiege || c.IsInBattle) cmsArmyCastle_UpgradeWalls.Enabled = false;
                        if (c.Towers == Castle.TowerLevels.Last() || !turn.CurrentPlayer.CanUpgradeTowers(c) || c.IsUnderSiege || c.IsInBattle) cmsArmyCastle_UpgradeTowers.Enabled = false;
                        if (c.Gatehouse == Castle.GatehouseLevels.Last() || !turn.CurrentPlayer.CanUpgradeGatehouse(c) || c.IsUnderSiege || c.IsInBattle) cmsArmyCastle_UpgradeGatehouse.Enabled = false;

                        cmsArmyCastle.Show(hexgridPanel1, e.X, e.Y);
                    }
                    else if (turn.CurrentPlayer.Armies.Contains(a))
                    {
                        cmsArmy_BuildBuilding.Enabled = true;
                        cmsArmy_BuildRoad.Enabled = true;

                        if (tm.GetBuilding(clickCoords) != null || turn.CurrentPlayer.BuildableBuildings.Count == 0 || !a.CanBuild || a.IsInBattle) cmsArmy_BuildBuilding.Enabled = false;
                        if (tm.GetBuilding(clickCoords) != null || !turn.CurrentPlayer.Race.CanPay("Road") || hex.SpecialType == "Road" || !a.CanBuild || a.IsInBattle || !a.CanBuildRoad(tm)) cmsArmy_BuildRoad.Enabled = false;

                        cmsArmy.Show(hexgridPanel1, e.X, e.Y);
                    }
                    else if (turn.CurrentPlayer.Towns.Contains(t))
                    {
                        cmsTown_MusterArmy.Enabled = true;
                        cmsTown_UpgradeTown.Enabled = true;
                        cmsTown_UpgradeObstacles.Enabled = true;
                        cmsTown_UpgradeWalls.Enabled = true;
                        cmsTown_UpgradeTowers.Enabled = true;

                        if (t.Level <= 5 || a != null || t.IsUnderSiege || t.IsInBattle) cmsTown_MusterArmy.Enabled = false;
                        if (t.Level == 20 || t.LevelChanged || !turn.CurrentPlayer.Race.CanPay("UpgradeTown") || t.IsUnderSiege || t.IsInBattle) cmsTown_UpgradeTown.Enabled = false;
                        if (t.Cover == Town.CoverLevels.Last() || !turn.CurrentPlayer.CanUpgradeCover(t) || t.IsUnderSiege || t.IsInBattle) cmsTown_UpgradeObstacles.Enabled = false;
                        if (t.Walls == Town.WallLevels.Last() || !turn.CurrentPlayer.CanUpgradeWalls(t) || t.IsUnderSiege || t.IsInBattle) cmsTown_UpgradeWalls.Enabled = false;
                        if (t.Towers == Town.TowerLevels.Last() || !turn.CurrentPlayer.CanUpgradeTowers(t) || t.IsUnderSiege || t.IsInBattle) cmsTown_UpgradeTowers.Enabled = false;

                        cmsTown.Show(hexgridPanel1, e.X, e.Y);
                    }
                    else if (turn.CurrentPlayer.Castles.Contains(c))
                    {
                        cmsCastle_MusterArmy.Enabled = true;
                        cmsCastle_UpgradeCastle.Enabled = true;
                        cmsCastle_UpgradeWalls.Enabled = true;
                        cmsCastle_UpgradeTowers.Enabled = true;
                        cmsCastle_UpgradeGatehouse.Enabled = true;

                        if (c.Level <= 2 || a != null || c.IsUnderSiege || c.IsInBattle) cmsCastle_MusterArmy.Enabled = false;
                        if (c.Level == 20 || c.LevelChanged || !turn.CurrentPlayer.Race.CanPay("UpgradeCastle") || c.IsUnderSiege || c.IsInBattle) cmsCastle_UpgradeCastle.Enabled = false;
                        if (c.Walls == Castle.WallLevels.Last() || !turn.CurrentPlayer.CanUpgradeWalls(c) || c.IsUnderSiege || c.IsInBattle) cmsCastle_UpgradeWalls.Enabled = false;
                        if (c.Towers == Castle.TowerLevels.Last() || !turn.CurrentPlayer.CanUpgradeTowers(c) || c.IsUnderSiege || c.IsInBattle) cmsCastle_UpgradeTowers.Enabled = false;
                        if (c.Gatehouse == Castle.GatehouseLevels.Last() || !turn.CurrentPlayer.CanUpgradeGatehouse(c) || c.IsUnderSiege || c.IsInBattle) cmsCastle_UpgradeGatehouse.Enabled = false;

                        cmsCastle.Show(hexgridPanel1, e.X, e.Y);
                    }
                }
            }

            UpdateResources();
            LoadMap();
            UpdateSummary();
            UpdateTooltips();
            Refresh();
        }
Пример #5
0
        private void hexgridPanel1_LeftClick(object sender, HexEventArgs e)
        {
            Army a = tm.GetArmy(e.Coords);
            MapObject b = tm.GetBuilding(e.Coords);
            clickCoords = e.Coords;

            //New object logic
            if (newObject != null)
            {
                if (tm.BoardHexes[clickCoords].StepCost(Hexside.North) == -1)
                {
                    MessageBox.Show("Can't place on immovable terrain");
                }

                else if (newObject.Coords != clickCoords)
                {
                    MessageBox.Show("Other building/enemy unit already on this spot");
                }
                else
                {
                    newObject.Coords = clickCoords;
                    Refresh();
                    newObject.Save();

                    newObjects.Remove(newObject);

                    if (newObjects.Count > 0)
                    {
                        newObject = newObjects.First();
                    }
                    else
                    {
                        newObject = null;
                    }
                }
                clickCoords = HexCoords.NewUserCoords(-1, -1);
            }

            else if (isPlayerTurn)
            {
                if (a != null)
                {
                    if (tm.SelectedArmy == a)
                    {
                        tm.SelectedArmy = null;
                    }
                    else if (turn.CurrentPlayer.Armies.Contains(a))
                    {
                        tm.SelectedArmy = a;
                    }
                }
                else
                {
                    tm.SelectedArmy = null;
                }
            }
            UpdateSummary();
            Refresh();
        }
Пример #6
0
        private void hexgridPanel1_HotspotHexChange(object sender, HexEventArgs e)
        {
            tm.HotspotHex = e.Coords;
            tm.GoalHex = e.Coords;
            MapObject b = tm.GetBuilding(e.Coords);
            Army a = tm.GetArmy(e.Coords);

            if (newObject != null && b == null && a == null)
            {
                newObject.Coords = e.Coords;
                tm.Los = new Fov(tm);
                tm.Los[e.Coords] = true;
            }

            Refresh();
            UpdateSummary();
        }