Example #1
0
    public void HighLightRangedMarks(int x, int y)
    {
        int maxRange = unit.UnitBodySpec.getMaxRange();
        int yrange, distance;

        for (int px = -maxRange; px <= maxRange; px++)
        {
            int tx = x + px;
            if (tx >= 0 && tx < sizex)
            {
                yrange = maxRange - Mathf.Abs(px);
                for (int py = -yrange; py <= yrange; py++)
                {
                    int ty = y + py;
                    if (ty >= 0 && ty < sizey)
                    {
                        distance = Mathf.Abs(tx - x) + Mathf.Abs(ty - y);
                        if (((UnitControl)PlayMap.GridController).HasSeenEnemyUnit(tx, ty, unit.playerFactionSpec))
                        {
                            if (distance > 1 && UnitControlBattle.canTarget(unit, ((UnitControl)PlayMap.GridController).getUnitData(tx, ty), distance))
                            {
                                TileSelect tile = PlayMap.Grid.getTileSpec(tx, ty);
//								Debug.Log ("RangePoint (" + tx + "," + ty +") for max " + maxRange);
                                tile.HighLightColorType = TileSelect.HighlightType.EnemyRTargetable;
                                highlightedTiles.Add(tile);
                            }
                        }
                    }
                }
            }
        }
    }
    public static void ShowAttackInfo(int x, int y)
    {
        if (GridController is UnitControl)
        {
            TileSelect tile = Grid.getTileSpec(x, y);
            bool       highlight, cursor;

            PlayMap.AttackInfo.SetActive(true);

            Menu.DefenderImage.UpdateUnitImage();

            AttackInfo        attackInformation    = (AttackInfo)PlayMap.AttackInfo.GetComponent("AttackInfo");
            UnitControlBattle UnitBattleController = ((UnitControl)GridController).getBattleController();
            float             attack               = UnitBattleController.AttackerPercentual100Damage();
            float             counter              = UnitBattleController.CounterPercentual100Damage();
            float             attackerHp           = UnitBattleController.Attacker.getPercentual100HP();
            float             defenderHp           = UnitBattleController.Defender.getPercentual100HP();
            attack *= attackerHp / 100.0f;
            float edefenderHp = defenderHp - attack;
            if (edefenderHp < 0)
            {
                edefenderHp = 0;
            }
            counter *= edefenderHp / 100.0f;
            float eattackerHp = attackerHp - counter;
            if (eattackerHp < 0)
            {
                eattackerHp = 0;
            }

            attackInformation.AttackDirection.text = UnitBattleController.AttackDirectionType();
            attackInformation.AttackerHP.text      = (int)(eattackerHp) + " %";
            attackInformation.DefenderHP.text      = (int)(edefenderHp) + " %";

            attackInformation.EstimateAttack.text = (int)attack + " %";
            if (counter > 0)
            {
                attackInformation.EstimateCounter.text = (int)counter + " %";
            }
            else
            {
                attackInformation.EstimateCounter.text = "--";
            }

            attackInformation.UnitName.text = UnitBattleController.Defender.name;
            attackInformation.UnitHP.text   = (int)defenderHp + " %";
        }
    }
Example #3
0
    private void dijkstraTest(int x, int y, int debt, OriginDirection d, bool firstmove)
    {
        int movement = unit.getMovement();

        UnitSpec.UnitMove movementType = unit.getMovementType();
        if (x >= 0 && x < this.sizex && y >= 0 && y < this.sizey && // within boundaries
            cost[x, y] >= 0 &&                                      // permission to map
            (x != originx || y != originy)                          // Not unit origin
            )
        {
            TileSelect tile = PlayMap.Grid.getTileSpec(x, y);
            if (tile.HighLightColorType != TileSelect.HighlightType.EnemyRTargetable &&             //Ignore if there is a ranged marker
                ((UnitControl)PlayMap.GridController).HasSeenEnemyUnit(x, y, unit.playerFactionSpec))
            {
                if (UnitControlBattle.canTarget(unit, ((UnitControl)PlayMap.GridController).getUnitData(x, y), 1))
                {
                    tile.HighLightColorType = TileSelect.HighlightType.EnemyTargetable;
                }
                else
                {
                    tile.HighLightColorType = TileSelect.HighlightType.Enemy;
                }
                highlightedTiles.Add(tile);
            }
            else
            {
                int newcost = getMovementCost(movementType, tile.FloorType, unit.UnitBodySpec.isAmphibious());
                if (newcost != 0)
                {
                    newcost += debt;
                    if ((newcost < cost[x, y] || cost[x, y] <= 0) && (firstmove || newcost <= movement))
                    {
                        cost[x, y]      = newcost;
                        direction[x, y] = d;
                        //tile.HighLightColorType = TileSelect.HighlightType.Movement;
                        highlightedTiles.Add(tile);
                        dijkstraTest(x, y + 1, newcost, OriginDirection.S, false);
                        dijkstraTest(x, y - 1, newcost, OriginDirection.N, false);
                        dijkstraTest(x + 1, y, newcost, OriginDirection.W, false);
                        dijkstraTest(x - 1, y, newcost, OriginDirection.E, false);
                    }
                }
            }
        }
    }
Example #4
0
 private void testTarget(int x, int y)
 {
     if (x >= 0 && x < this.sizex && y >= 0 && y < this.sizey)
     {
         TileSelect tile = PlayMap.Grid.getTileSpec(x, y);
         if (tile.HighLightColorType != TileSelect.HighlightType.EnemyRTargetable &&             //Ignore if there is a ranged marker
             ((UnitControl)PlayMap.GridController).HasSeenEnemyUnit(x, y, unit.playerFactionSpec))
         {
             if (UnitControlBattle.canTarget(unit, ((UnitControl)PlayMap.GridController).getUnitData(x, y), 1))
             {
                 tile.HighLightColorType = TileSelect.HighlightType.EnemyTargetable;
             }
             else
             {
                 tile.HighLightColorType = TileSelect.HighlightType.Enemy;
             }
             highlightedTiles.Add(tile);
         }
     }
 }
    public override void clickCoordinate(int x, int y)
    {
        bool pathconfirming = false;

        if (PlayMap.LockMovement)
        {
            TileSelect tile = PlayMap.Grid.getTileSpec(x, y);
            if (tile.HighLightColorType == TileSelect.HighlightType.EnemyTargetable || tile.HighLightColorType == TileSelect.HighlightType.EnemyRTargetable)
            {
                if (selectTileX == x && selectTileY == y)
                {
                    confirmAttack();
                }
                else
                {
                    var      unit     = UnitPlacement [selectUnitX, selectUnitY];
                    GameUnit unitStat = (GameUnit)unit.GetComponent("GameUnit");
                    UnitBattleController = UnitControlBattle.CalculateBattle(unitStat, targetTileX, targetTileY, x, y);
                    PlayMap.ShowAttackInfo(x, y);
                }
            }
            else
            {
                PlayMap.HideAttackInfo();
            }
            selectTileX = x;
            selectTileY = y;
        }
        else if (UnitPlacement [x, y] != null)
        {
            //Set tile selection
            TileSelect tile = PlayMap.Grid.getTileSpec(x, y);

            if (selectUnitX >= 0 &&                                                  // there is a unit already selected
                tile.HighLightColorType == TileSelect.HighlightType.EnemyTargetable) // selecting enemy target for direct combat

//				Debug.Log("ENGAGE!");
            //Second choosing of the same tile
            {
                if (selectTileX == x && selectTileY == y && confirmPath && UnitMovementController.getRouteSize() > 0)
                {
                    confirmMovement();
                }
                else
                {
                    GameUnit unit = (GameUnit)UnitPlacement[selectUnitX, selectUnitY].GetComponent("GameUnit");
                    if (!unit.HasMoved)
                    {
                        pathconfirming = UnitMovementController.attackSelect(x, y, unit);
                    }
                }
                selectTileX = x;
                selectTileY = y;
            }
            else if (tile.HighLightColorType == TileSelect.HighlightType.EnemyRTargetable)              // selecting indirect combat
//				Debug.Log("BOMBARD!");
            {
                selectTileX = x;
                selectTileY = y;
            }
            else
            {
                selectTileX = x;
                selectTileY = y;

                if (selectUnitX == x && selectUnitY == y)                  //Same unit
                {
                    confirmMovement();
                }
                else
                {
                    // a unit was selected

                    //				Debug.Log("ATTENTION!");

                    UnitMovementController.fullclear();

                    GameUnit unit = (GameUnit)UnitPlacement[selectTileX, selectTileY].GetComponent("GameUnit");
                    if (!unit.HasMoved)
                    {
                        selectUnitX = x;
                        selectUnitY = y;
                        UnitMovementController.mapMovement(x, y, unit);
                    }
                }
            }
        }
        else
        {
            if (selectUnitX >= 0)
            {
                //Second choosing of the same tile
                if (selectTileX == x && selectTileY == y && confirmPath && UnitMovementController.getRouteSize() > 0)
                {
                    confirmMovement();
                }
                else
                {
                    //Set tile selection
                    selectTileX = x;
                    selectTileY = y;

                    GameUnit unit = (GameUnit)UnitPlacement[selectUnitX, selectUnitY].GetComponent("GameUnit");
                    if (!unit.HasMoved)
                    {
                        pathconfirming = UnitMovementController.selectPath(x, y, unit);
                    }
                    if (!pathconfirming)                      // no valid selection
                    {
                        selectUnitX = selectTileX = -1;
                        selectUnitY = selectTileY = -1;

                        UnitMovementController.fullclear();
                    }
                }
            }
            else
            {
                //Set tile selection
                selectTileX = x;
                selectTileY = y;
            }
        }


        confirmPath = pathconfirming;

        if (selectTileX >= 0)
        {
            placeSelectHighlight(x, y);
        }
        else
        {
            removeSelectHighlight();
        }
    }