Esempio n. 1
0
        public static int getTargetFutureDamage(BattleUnit unit, BattleUnit target, int CTR)
        {
            /*
             * This function calculates the amount of damage to be inflicted upon a unit from actions
             * targetted at that unit's x,y location before a given CTR value
             */
            BattleQueue         queue   = GameBattle.getQueue();
            int                 damage  = 0;
            List <BattleAction> actions = queue.getActions(target.X, target.Y, CTR);

            actions.ForEach(action => damage += BattleAction.getDamage(unit, target, action.actiondef));
            return(damage);
        }
Esempio n. 2
0
        public static double getTileSafetyScore(List <BattleUnit> units, BattleUnit unit, int x, int y)
        {
            double safetyScore = 0;

            foreach (BattleUnit u in units)
            {
                if (u.Equals(unit))
                {
                    continue;
                }

                int    dx       = x - u.X;
                int    dy       = y - u.Y;
                double distance = Math.Sqrt(dx * dx + dy * dy);
                if (u.team == unit.team)
                { //distance from ally
                    safetyScore += (distance == 0) ? 1 : (1 / distance);
                }
                else
                { //distance from enemy
                    safetyScore -= (distance == 0) ? 1 : (1 / distance);
                }
            }

            //check queue for future action spreads that hit this tile
            List <BattleAction> actions = GameBattle.getQueue().getActions(x, y, 20); //find all actions under 20 ctr

            actions.ForEach(action => {
                // "what if" the unit moved to the proposed x,y?
                int damage = BattleAction.getDamage(action.actor, unit, action.actiondef);
                if (damage > 0)
                { //unit would be damaged
                    safetyScore -= 1;
                }
                if (unit.hp - damage < 0)
                { //unit would be killed
                    safetyScore -= 2;
                }
                if (damage < 0)
                { //unit would be healed
                    safetyScore += 1;
                }
            });

            return(safetyScore);
        }