Example #1
0
        public override void Handle(Event e)
        {
            switch (e.GetEventType())
            {
            case EventType.NameEvent:
                NameEvent ne = (NameEvent)e;
                Game.Log.Add(
                    string.Format(
                        "{0}<{2}> is now known as {1}<{2}>.",
                        Game.World.GetPlayer(ne.ID).Name,
                        ne.Name,
                        ne.ID
                        )
                    );
                break;

            case EventType.BuildUnitEvent:
                //this should probably not be a thing later,
                //because unit building units takes time?
                //(so it'd actually be annoying)
                //but right now it's instant and you probably want it
                //selected asap

                BuildUnitEvent bue = (BuildUnitEvent)e;

                if (ui.Selection == null)
                {
                    break;
                }

                Vector2i selected = ui.Selection.GetSelection();

                //reselect, so our tile selection -> unit selection
                //still clunky, but it's what we go with for now
                if (bue.x == selected.X && bue.y == selected.Y)
                {
                    ui.Select(new Vector2i(bue.x, bue.y));
                }
                break;

            default:
                throw new ArgumentException();
            }
        }
Example #2
0
        public void ReceiveInput(string s)
        {
            MovementInput(s);
            DevInput(s);

            switch (s)
            {
            case "force-quit":
                ui.Engine.Exit();
                break;

            case "quit":
                if (ui.Mode == InterfaceMode.Normal)
                {
                    ui.Engine.Exit();
                }
                else
                {
                    ui.Mode = InterfaceMode.Normal;
                }
                break;

            case "warp":
                if (ui.SelectedUnit != null)
                {
                    ui.Mode = InterfaceMode.TargettingWarp;
                }
                break;

            case "bombard":
                if (ui.SelectedUnit != null)
                {
                    if (
                        ui.SelectedUnit.HasAbility(
                            UnitAbilites.Bombarding
                            ) && ui.SelectedUnit.Attacks > 0
                        )
                    {
                        ui.Mode = InterfaceMode.TargettingBombard;
                    }
                }
                break;

            case "pass":
                if (game.OurTurn)
                {
                    ui.Engine.NetClient.Send(
                        new NetMessage3(NM3MessageType.client_pass)
                        );
                }
                else
                {
                    game.Log.Add("Not your turn!");
                }
                break;

            case "select-next-idle":
                ui.Mode = InterfaceMode.Normal;

                List <Unit> selectable =
                    game.World.GetPlayerUnits(game.LocalPlayer.ID)
                    .Select(id => game.World.Units[id])
                    .Where(u => u.Attacks > 0 || u.Moves > 0)
                    .ToList()
                ;

                if (selectable.Count > 0)
                {
                    if (ui.SelectedUnit != null)
                    {
                        int index = selectable.IndexOf(ui.SelectedUnit);
                        //if the selected is not one of ours, we get -1
                        //which still works with the code (because the
                        //new selected index then becomes 0)
                        //which is absolutely fine
                        //only works with forward selection though.

                        index = (index + 1) % selectable.Count;

                        ui.Select(selectable[index].Position);
                    }
                    else
                    {
                        ui.Select(selectable[0].Position);
                    }
                }
                break;
            }
        }