Ejemplo n.º 1
0
        //Keep track of the two latest tiles to calc direction
        private IQPathTile[] LastTwoTiles(IQPathTile t)
        {
            if (twins == null)
            {
                twins = new IQPathTile[2];
            }

            if (t == null)
            {
                return(twins);
            }

            if (twins.Length == 0)
            {
                twins[0] = t;
            }
            if (twins.Length == 1)
            {
                twins[1] = t;
            }
            if (twins.Length == 2)
            {
                twins[0] = twins[1];
                twins[1] = t;
            }
            if (twins.Length > 2)
            {
                Debug.LogError("twins.Length > 2");
            }

            return(twins);
        }
Ejemplo n.º 2
0
 public float AggregateTileCostToEnter(float costSoFar, IQPathTile sourcetile, IQPathUnit theUnit)
 {
     // TODO: We are ignoring source tile for now, will change soon
     // return ((Unit)theUnit).TotalTurnsToEnterHex(this, costSoFar);
     //return BaseMovementCost();
     return(((Unit)theUnit).TotalTurnsToEnterHex((Hex)sourcetile, costSoFar));
     //throw new System.NotImplementedException();
 }
Ejemplo n.º 3
0
    // cost in turns
    public float CostToEnterHex(IQPathTile sourceTile, IQPathTile destinationTile)
    {
        // return 1;

        // there doesn't appear to be anything that uses this


        return(MovementCostToEnterHex((Hex)destinationTile));
    }
Ejemplo n.º 4
0
Archivo: Map.cs Proyecto: cyv-cg/FE
    public static Cell GetCellData(Vector2Int position)
    {
        IQPathTile tile = null;

        for (int i = Layers.Count - 1; i >= 0; i--)
        {
            if (Layers[i].ContainsKey(position))
            {
                tile = Layers[i][position];
                break;
            }
            else
            {
                continue;
            }
        }

        return((Cell)tile);
    }
Ejemplo n.º 5
0
Archivo: Map.cs Proyecto: cyv-cg/FE
    public static Cell[] GetMoveArea(Fighter f, int movement, bool weighted = true)
    {
        Dictionary <Cell, int> depths = GetTileDepths(f, movement + 1);

        Cell[] tiles = new Cell[depths.Count];
        depths.Keys.CopyTo(tiles, 0);

        if (weighted)
        {
            IQPathTile  startCell = UnitTile(f);
            List <Cell> range     = new List <Cell>
            {
                (Cell)startCell
            };

            foreach (Cell c in tiles)
            {
                Fighter unitInTile = c.unitInTile;

                IQPathTile[] path = QPath.FindPath(f, startCell, c, Cell.EstimateDistance);
                if (!c.impassible && AggregateCost(path, f.Unit) <= movement && c.MoveCost(f.Unit) >= 0 && (unitInTile == null || unitInTile.Unit.alignment == f.Unit.alignment))
                {
                    range.Add(c);
                    c.Display_Debug(AggregateCost(path, f.Unit).ToString());
                }
            }

            List <Cell> all = range;
            range = new List <Cell>();
            foreach (Cell c in all)
            {
                if (c.unitInTile == null || c.unitInTile == f)
                {
                    range.Add(c);
                }
            }

            return(range.ToArray());
        }

        return(tiles);
    }
Ejemplo n.º 6
0
Archivo: Map.cs Proyecto: cyv-cg/FE
    public static Cell[] GetNeighbors(Cell c)
    {
        Vector2Int  cellPosition = c.position;
        List <Cell> cells        = new List <Cell>();

        IQPathTile[] tiles = new IQPathTile[4]
        {
            GetCellData(cellPosition + Vector2Int.up),
            GetCellData(cellPosition + Vector2Int.right),
            GetCellData(cellPosition + Vector2Int.down),
            GetCellData(cellPosition + Vector2Int.left)
        };

        foreach (Cell t in tiles)
        {
            if (t != null)
            {
                cells.Add(t);
            }
        }

        return(cells.ToArray());
    }
Ejemplo n.º 7
0
 public float AggregateCostToEnter(float costSoFar, IQPathTile sourceTile, IQPathUnit theUnit)
 {
     //TODO: We are ignoring source tile atm, this will need to change with rivers
     return(((Unit)theUnit).AggregateTurnsToEnterHex(this, costSoFar));
 }
Ejemplo n.º 8
0
 public static float CostEstimate(IQPathTile aa, IQPathTile bb)
 {
     return(Distance((Tile)aa, (Tile)bb));
 }
Ejemplo n.º 9
0
 public float CostToEnterTile(IQPathTile sourceTile, IQPathTile destinationTile)
 {
     //Debug.Log("CostToEnterTile");
     return(1f);
 }
Ejemplo n.º 10
0
    //public static float Distance(Hex a, Hex b)
    //{
    //    return
    //        Mathf.Max(
    //            Mathf.Abs(a.Q - b.Q),
    //            Mathf.Abs(a.R - b.R),
    //            Mathf.Abs(a.S - b.S)
    //        );
    //}

    public static float CostEstimate(IQPathTile aa, IQPathTile bb)
    {
        // heuristic function for a-star. Maybe pad distance based on tile type
        // to smooth out pathfinding
        return(Distance((Hex)aa, (Hex)bb));
    }
Ejemplo n.º 11
0
 public float AggregateCostToEnter(float costSoFar, IQPathTile sourceTile, IQPathUnit theUnit)
 {
     // TODO: We are ignoring source tile right now, this will have to change when
     // we have rivers.
     return(((Unit)theUnit).AggregateTurnsToEnterHex(this, costSoFar));
 }
Ejemplo n.º 12
0
 public float AggregateCostToEnter(float costSoFar, IQPathTile sourceTile, IQPathUnit theUnit)
 {
     return(((Unit)theUnit).AggregateTurnsToEnterTile(this, costSoFar));
 }
Ejemplo n.º 13
0
 public float AggregateCostToEnter(float costSoFar, IQPathTile sourceTile, IQPathTile[] twins, IQPathUnit theUnit)
 {
     return ((_Enemy)theUnit).TileToTileCost(this, twins);
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Turn cost to enter a hex (i.e. 0.5 turns if a movement cost is 1 and we have 2 max movement)
 /// </summary>
 public float CostToEnterHex(IQPathTile sourceTile, IQPathTile destinationTile)
 {
     return(1);
 }
Ejemplo n.º 15
0
 //TEMP - TODO: FIX ME! (in Unit.cs too)
 public static float CostEstimate(IQPathTile aa, IQPathTile bb)
 {
     return(Distance((Hex)aa, (Hex)bb)); //assume these parameters are hexes
 }
Ejemplo n.º 16
0
 public float AggregateCostToEnter(float costSoFar, IQPathTile sourceTile, IQPathUnit unit)
 {
     return(((Unit)(unit)).AggregateTurnsToEnterHex(this, costSoFar));
 }
Ejemplo n.º 17
0
 public static float CostEstimate(IQPathTile a, IQPathTile b)
 {
     return(Distance((Hex)a, (Hex)b));
 }
Ejemplo n.º 18
0
    public float AggregateCostToEnter(float costSoFar, IQPathTile sourceTile, IQPathUnit unit)
    {
        Fighter f = (Fighter)unit;

        return((f).AggregateTurnsToEnterTile(this, costSoFar) + MoveCost(f.Unit));
    }
Ejemplo n.º 19
0
    public static float EstimateDistance(IQPathTile a, IQPathTile b)
    {
        Cell s = (Cell)a, e = (Cell)b;

        return(Vector2.Distance(s.transform.position, e.transform.position));
    }
Ejemplo n.º 20
0
 public float CostToEnterHex(IQPathTile sourceTile, IQPathTile destinationTile)
 {
     return(1);                        // Turn cost to enter a hex (i.e. 0.5 turns if a movement cost is 1 and we have 2 max movement)
 }
 public float AggregateCostToEnter(float costSoFar, IQPathTile sourceTile, IQPathUnit theUnit)
 {
     //throw new System.NotImplementedException();
     //todo we are ignoring source tile right now, this will have to change when we have rivers
     return(((Unit)theUnit).AggregateTurnsToEnterHex(this, costSoFar));
 }
Ejemplo n.º 22
0
        public Offensive(Fighter attacker, Fighter defender, bool repeated = false)
        {
            Attacker = attacker;
            Defender = defender;

            Seed = StatsCalc.Seed(new Vector2Int[2] {
                attacker.Position(), defender.Position()
            });
            Rand = new System.Random(Seed);

            IsPhysical = Attacker.Weapon.isPhysical;

            AtkStat = IsPhysical ? Attacker.Unit.stats.strength : Attacker.Unit.stats.magic;
            DefStat = IsPhysical ? Defender.Unit.stats.defense : Defender.Unit.stats.resistance;

            Cell = Map.UnitTile(Attacker);

            Support1 = StatsCalc.SupportBonus(Attacker);
            Support2 = StatsCalc.SupportBonus(Defender);

            TriangleBonus = StatsCalc.TriangleBonus(Attacker, Defender);
            TerrainBonus1 = StatsCalc.TerrainBonus(Map.UnitTile(Attacker));
            TerrainBonus2 = StatsCalc.TerrainBonus(Map.UnitTile(Defender));

            Speed1 = Attacker.Unit.stats.speed;
            Speed2 = Defender.Unit.stats.speed;

            Wgt1 = Attacker.Weapon.weight;
            Wgt2 = Defender.Weapon.weight;

            Con1 = Attacker.Unit.stats.constitution;
            Con2 = Defender.Unit.stats.constitution;

            Attack  = AtkStat;
            Defense = DefStat;

            Spd1 = StatsCalc.AttackSpeed(Speed1, Wgt1, Con1);
            Spd2 = StatsCalc.AttackSpeed(Speed2, Wgt2, Con2);

            Atk = StatsCalc.PhysicalAttack(Attack, Attacker.Weapon.might, TriangleBonus, StatsCalc.WeaponEffectiveness(Attacker.Weapon, Defender), Support1, false);
            Def = StatsCalc.PhysicalDefense(TerrainBonus2, Defense, Support2);

            HitRate = StatsCalc.HitRate(Attacker.Weapon.hit, Attacker.Unit.stats.skill, Attacker.Unit.stats.luck, Support1);
            Avoid   = StatsCalc.Avoid(Speed2, Defender.Unit.stats.luck, TerrainBonus2, Support2);
            Acc     = StatsCalc.Accuracy(HitRate, Avoid, TriangleBonus);

            CritRate   = StatsCalc.CriticalRate(Attacker.Weapon.crit, Attacker.Unit.stats.skill, Support1, StatsCalc.ClassCrit(Attacker.Unit.unitClass));
            CritEvade  = StatsCalc.CriticalEvade(Defender.Unit.stats.luck, Support2);
            CritChance = StatsCalc.CriticalChance(CritRate, CritEvade);

            if (StatsCalc.ClassCriticalModifier.ContainsKey(Attacker.Unit.unitClass))
            {
                CritChance += StatsCalc.ClassCriticalModifier[Attacker.Unit.unitClass];
            }

            if (repeated)
            {
                CritChance += Attacker.Unit.stats.pursuitCriticalCoefficient;
            }

            Hit  = Rand.Next(0, 100) <= Acc;
            Crit = Rand.Next(0, 100) <= CritChance;

            Damage = Crit ? StatsCalc.CriticalDamage(StatsCalc.Damage(Atk, Def)) : StatsCalc.Damage(Atk, Def);

            if (Attacker.LastTarget == Defender)
            {
                Attacker.RepeatedTarget++;
            }
            else
            {
                Attacker.LastTarget     = Defender;
                Attacker.RepeatedTarget = 0;
            }
        }
Ejemplo n.º 23
0
 public float MovmementValue(IQPathTile SourceTile, IQPathTile destinationTile)
 {
     return(1);
 }