Ejemplo n.º 1
0
    // NOTE: can be null
    void HexTileClicked()
    {
        BattleTile clickedTile = this.hoveredTile;

        if (this.state == BattleState.SelectingAction)
        {
            if (clickedTile != this.selectedTile)
            {
                if (this.selectedTile)
                {
                    // Unselected this tile.

                    this.mapDisplay.DisableSelectedTiles();
                    this.mapDisplay.DisableTargetTile();
                }
                this.selectedTile = clickedTile;
                if (this.selectedTile)
                {
                    // Selected this tile.

                    this.mapDisplay.SetSelectedTile(this.selectedTile.mapTile);

                    BattleMech mech = this.selectedTile.mech;

                    if (mech)
                    {
                        this.UpdateTargetTile(mech);
                    }
                }
                else
                {
                    // Just for a consistent look when no tile is selected.
                    this.BringTileTabButtonToFront(this.uiRefs.mechTabButton);
                }

                this.AdjustTileInfoTabButtonGraphics();
                this.UpdateRightPanel();
            }
        }
        else if (this.state == BattleState.MoveAction)
        {
            if (clickedTile)
            {
                BattleMech mech = this.selectedTile.mech;

                var move = new BattleMove.Move();
                move.mechIndex = mech.tile.index;
                move.newIndex  = clickedTile.index;
                move.isFiring  = mech.target != null && mech.fireAuto;
                if (move.isFiring)
                {
                    move.targetMechIndex = mech.target.tile.index;
                }
                this.ExecuteMove(move);

                this.moveActionData.moved = true;

                // Make this the new selected tile.
                this.selectedTile = clickedTile;
                this.mapDisplay.SetSelectedTile(this.selectedTile.mapTile);

                this.UpdateTargetTile(this.selectedTile.mech);
                this.UpdateRightPanel();

                this.SetState(BattleState.EndOfAction);
            }
            else
            {
                this.SetState(BattleState.EndOfAction);
            }
        }
        else if (this.state == BattleState.SetTargetAction)
        {
            BattleMech mech = this.selectedTile.mech;

            var move = new BattleMove.SetTarget();
            move.mechIndex = mech.tile.index;
            move.hasTarget = clickedTile != null;
            if (move.hasTarget)
            {
                move.targetMechIndex = clickedTile.index;
            }
            this.ExecuteMove(move);

            // TODO: Keep mech's dir pointed towards its target, if it has one
            this.UpdateTargetTile(mech);

            this.UpdateRightPanel();

            this.SetState(BattleState.EndOfAction);
        }
    }
Ejemplo n.º 2
0
    public void Update()
    {
        // Test: path to a target mech, stop when we can see it and keep firing.
        BattleMech target = null;

        foreach (BattleTeam team in this.battle.teams)
        {
            foreach (BattleMech mech in team.mechs)
            {
                if (team != this.ourMech.team)
                {
                    target = mech;
                    break;
                }
            }
        }

        if (target == null)
        {
            return;
        }

        BattleTile ourTile    = this.ourMech.tile;
        BattleTile targetTile = target.tile;

        bool canSeeTarget = this.battle.TestLOS(ourTile, targetTile);

        // TODO: this is really stupid
        this.battle.pathNetwork.SetNodeEnabled(ourTile, true);
        this.battle.pathNetwork.SetNodeEnabled(targetTile, true);
        PathingResult result = this.battle.pathNetwork.FindPath(ourTile, targetTile);

        this.battle.pathNetwork.SetNodeEnabled(ourTile, false);
        this.battle.pathNetwork.SetNodeEnabled(targetTile, false);

        if (result.isValid == false)
        {
            return;
        }

        BattleTile nextTile = (BattleTile)result.nodes[1];

        if (canSeeTarget && result.distance <= 5)
        {
            var move = new BattleMove.StandingFire();
            move.mechIndex       = ourTile.index;
            move.targetMechIndex = targetTile.index;
            this.battle.ExecuteMove(move);
        }
        else
        {
            var move = new BattleMove.Move();
            move.mechIndex = ourTile.index;
            move.newIndex  = nextTile.index;
            if (canSeeTarget)
            {
                move.isFiring        = true;
                move.targetMechIndex = targetTile.index;
            }
            else
            {
                move.isFiring = false;
            }
            this.battle.ExecuteMove(move);
        }

        this.battle.SetState(BattleState.EndOfAction);
    }