示例#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);
        }
示例#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);
        }
示例#3
0
        public void invoke(BattleMap map, List <BattleUnit> units, BattleQueue queue)
        {
            GameBattle.WriteLine(name + " invoked");

            //this.safetyMap = generateSafetyMap(battle.units, this);
            List <BattleAction> coverage = BattleAction.generateCoverage(map, units, this);

            if (!moved && !acted)
            {
                if (action != null)
                {
                    GameBattle.WriteLine(name + " is already preparing to act.");
                    //todo: if action is sticky, allow movement
                    acted = true;
                }
                else
                {
                    action = coverage.First();  //supposedly the best action

                    //if action requires move
                    if (action.node.x != X || action.node.y != Y)
                    {
                        move = new BattleMove(this, action.node, action.moveNodes);
                        queue.add(move);
                        moved  = true;
                        action = null; //will get new action after move is completed
                    }
                    else
                    {
                        queue.add(action);
                        acted = true;
                        GameBattle.WriteLine(name + " queued an action called " + action.actiondef.name);
                    }
                }
            }
            else if (acted && !moved)
            {
                GameBattle.WriteLine("Moving to a safer location.");

                List <MoveNode> moveNodes = BattleMap.getMoveNodes(map.tiles, GameBattle.MAP_WIDTH, GameBattle.MAP_HEIGHT, units, this, moveLimit, true);

                moveNodes.Sort();

                MoveNode newNode = moveNodes[0];
                move = new BattleMove(this, newNode, action.moveNodes);
                queue.add(move);

                //only counts as move if actually moved
                if (newNode.x != X || newNode.y != Y)
                {
                    moved = true;
                }

                done();
            }
            else if (!acted && moved)
            {
                if (action != null)
                {
                    GameBattle.WriteLine(name + " is already preparing to act!!!");
                }
                else
                {
                    action = coverage[0];
                    queue.add(action);
                    acted = true;
                    GameBattle.WriteLine(name + " queued an action called " + action.actiondef.name);
                }

                done();
            }
            else
            {
                GameBattle.WriteLine("This should never happen.");
                done();
            }
        }