public override Pod SetupState(ProgramContext ProgramContext, ProgramStateContext ProgramStateContext)
        {
            _Context        = (MatchContext)ProgramStateContext;
            _MatchEndBuffer = new EventBuffer <EventArgs>();

            var renderer = new UnitConfigurationRenderer(
                _Context.Match.Scenario,
                GameData.UnitRenderDetails,
                128,
                1024,
                ClassLibrary.Instance.GetFont("compacta"));
            var factionRenderer =
                new FactionRenderer(_Context.Match.Scenario, GameData.FactionRenderDetails, 512, 1024);
            var armies = new HashSet <Army>(_Context.GetPlayerControlledArmies());

            var screen = new MatchScreen(
                ProgramContext.ScreenResolution,
                _Context.Match,
                armies,
                GameData.TileRenderers[_Context.Match.Scenario.Environment.UniqueKey],
                renderer,
                factionRenderer);
            var controller =
                new HumanMatchPlayerController(
                    _Context.MakeMatchAdapter(), armies, renderer, screen, ProgramContext.KeyController);

            var playerControllers = new Dictionary <Army, MatchPlayerController>();

            foreach (Army a in _Context.Match.Armies)
            {
                // var controller = new AIMatchPlayerController(_Context.MakeMatchAdapter(), a);
                var overrideController = _Context.GetOverridePlayerController(a);
                playerControllers.Add(a, overrideController ?? controller);
            }
            _MatchController             = new MatchController(_Context.Match, playerControllers);
            screen.OnPulse              += HandlePulse;
            _Context.Match.OnMatchEnded += _MatchEndBuffer.Hook <EventArgs>(HandleMatchEnd).Invoke;
            _Context.Match.Start();

            return(screen);
        }
        public HumanMatchPlayerController(
            MatchAdapter Match,
            IEnumerable <Army> AllowedArmies,
            UnitConfigurationRenderer UnitConfigurationRenderer,
            MatchScreen MatchScreen,
            KeyController KeyController)
        {
            _NewUnitBuffer = new EventBuffer <ValuedEventArgs <UnitView> >();

            this.Match                     = Match;
            this.AllowedArmies             = new HashSet <Army>(AllowedArmies);
            this.UnitConfigurationRenderer = UnitConfigurationRenderer;

            _MatchScreen = MatchScreen;
            _MatchScreen.OnFinishClicked += EndTurn;
            _MatchScreen.OnUnitAdded     += _NewUnitBuffer.Hook <ValuedEventArgs <UnitView> >(AddUnit).Invoke;
            _MatchScreen.OnPulse         += (sender, e) => _NewUnitBuffer.DispatchEvents();

            _Controllers = new Dictionary <TurnComponent, Subcontroller>
            {
                { TurnComponent.DEPLOYMENT, new DeploymentController(this) },
                { TurnComponent.AIRCRAFT, new AircraftController(this) },
                { TurnComponent.ANTI_AIRCRAFT, new AntiAircraftController(this) },
                { TurnComponent.ARTILLERY, new ArtilleryController(this) },
                { TurnComponent.ATTACK, new AttackController(this) },
                { TurnComponent.VEHICLE_COMBAT_MOVEMENT, new OverrunController(this) },
                { TurnComponent.VEHICLE_MOVEMENT, new MovementController(this, true) },
                { TurnComponent.CLOSE_ASSAULT, new CloseAssaultController(this) },
                { TurnComponent.NON_VEHICLE_MOVEMENT, new MovementController(this, false) },
                { TurnComponent.RESET, new NoOpController(this) },
                { TurnComponent.WAIT, new NoOpController(this) },
                { TurnComponent.SPECTATE, new NoOpController(this) }
            };

            foreach (TileView t in MatchScreen.MapView.TilesEnumerable)
            {
                t.OnClick      += OnTileClick;
                t.OnRightClick += OnTileRightClick;
            }
            foreach (UnitView u in _MatchScreen.UnitViews)
            {
                AddUnit(u);
            }
            _KeyController              = KeyController;
            KeyController.OnKeyPressed += OnKeyPressed;

            MatchScreen.LoadButton.OnClick +=
                (sender, e) => LoadUnit(_CurrentTurn.TurnComponent != TurnComponent.DEPLOYMENT);
            MatchScreen.UnloadButton.OnClick         += (sender, e) => UnloadUnit();
            MatchScreen.FortifyButton.OnClick        += (sender, e) => FortifyUnit();
            MatchScreen.AbandonButton.OnClick        += (sender, e) => AbandonUnit();
            MatchScreen.DismountButton.OnClick       += (sender, e) => Dismount();
            MatchScreen.MountButton.OnClick          += (sender, e) => Mount();
            MatchScreen.EvacuateButton.OnClick       += (sender, e) => Evacuate();
            MatchScreen.ReconButton.OnClick          += (sender, e) => Recon();
            MatchScreen.ClearMinefieldButton.OnClick += (sender, e) => ClearMinefield();
            MatchScreen.EmplaceButton.OnClick        += (sender, e) => Emplace();

            _AllowedActions = new Dictionary <Button, Func <bool> >
            {
                { MatchScreen.LoadButton, () => _Controllers[_CurrentTurn.TurnComponent].CanLoad() },
                { MatchScreen.UnloadButton, () => _Controllers[_CurrentTurn.TurnComponent].CanUnload() },
                { MatchScreen.FortifyButton, () => _Controllers[_CurrentTurn.TurnComponent].CanFortify() },
                { MatchScreen.AbandonButton, () => _Controllers[_CurrentTurn.TurnComponent].CanAbandon() },
                { MatchScreen.DismountButton, () => _Controllers[_CurrentTurn.TurnComponent].CanDismount() },
                { MatchScreen.MountButton, () => _Controllers[_CurrentTurn.TurnComponent].CanMount() },
                { MatchScreen.EvacuateButton, () => _Controllers[_CurrentTurn.TurnComponent].CanEvacuate() },
                { MatchScreen.ReconButton, () => _Controllers[_CurrentTurn.TurnComponent].CanRecon() },
                {
                    MatchScreen.ClearMinefieldButton,
                    () => _Controllers[_CurrentTurn.TurnComponent].CanClearMinefield()
                },
                { MatchScreen.EmplaceButton, () => _Controllers[_CurrentTurn.TurnComponent].CanEmplace() }
            };
        }