protected List <int> get_targets()
        {
            Game_Unit  unit         = get_unit();
            List <int> temp_targets = new List <int>();

            switch (Mode)
            {
            // Looking for people to rescue
            case 0:
                List <int> rescue_targets = unit.allies_in_range(1);
                foreach (int id in rescue_targets)
                {
                    if (unit.can_rescue(Global.game_map.units[id]))
                    {
                        temp_targets.Add(id);
                    }
                }
                break;

            // Looking for drop locations
            case 1:
                foreach (Vector2 loc in unit.drop_locs())
                {
                    temp_targets.Add((int)(loc.X + loc.Y * Global.game_map.width));
                }

                /*foreach (Vector2 loc in new Vector2[] { new Vector2(0, 1), new Vector2(0, -1), new Vector2(1, 0), new Vector2(-1, 0) }) //Debug
                 *  if (!Global.game_map.is_off_map(loc + unit.loc))
                 *      if (!Global.game_map.is_blocked(loc + unit.loc, unit.rescuing))
                 *          if (Pathfinding.passable(Global.game_map.units[unit.rescuing], loc + unit.loc))
                 *              temp_targets.Add((int)((loc + unit.loc).X + (loc + unit.loc).Y * Global.game_map.width));*/
                break;

            // Looking for people to take
            case 2:
                List <int> take_targets = unit.allies_in_range(1);
                foreach (int id in take_targets)
                {
                    if (Global.game_map.units[id].different_team(unit))
                    {
                        continue;
                    }
                    if (!Global.game_map.units[id].is_rescuing)
                    {
                        continue;
                    }
                    if (unit.can_rescue(Global.game_map.units[Global.game_map.units[id].rescuing]))
                    {
                        temp_targets.Add(id);
                    }
                }
                break;

            // Looking for people to give to
            case 3:
                List <int> give_targets = unit.allies_in_range(1);
                foreach (int id in give_targets)
                {
                    if (Global.game_map.units[id].different_team(unit))
                    {
                        continue;
                    }
                    if (Global.game_map.units[id].is_rescuing)
                    {
                        continue;
                    }
                    if (!Global.game_map.units[id].is_rescue_blocked() &&
                        Global.game_map.units[id].can_rescue(Global.game_map.units[unit.rescuing]))
                    {
                        temp_targets.Add(id);
                    }
                }
                break;

            // Skills: Savior
            // Looking for people to cover
            case 4:
                List <int> cover_targets = unit.allies_in_range(1);
                foreach (int id in cover_targets)
                {
                    if (unit.can_rescue(Global.game_map.units[id]))
                    {
                        if (Pathfind.passable(unit, Global.game_map.units[id].loc))
                        {
                            temp_targets.Add(id);
                        }
                    }
                }
                break;

            // Looking for people to take refuge under
            case 5:
                List <int> refuge_targets = unit.allies_in_range(1);
                foreach (int id in refuge_targets)
                {
                    Game_Unit target = Global.game_map.units[id];
                    if (target.has_refuge() && target.can_rescue(unit))
                    {
                        temp_targets.Add(id);
                    }
                }
                break;
            }
            return(temp_targets);
        }
Exemple #2
0
        private void AddSkillCommands(ref List <string> commands, Game_Unit unit)
        {
            // Actions:
            //   100 = Shelter
            //   101 = Dash
            //   102 = Swoop
            //   103 = Trample
            //   104 = Sacrifice
            //   105 = Refuge
            //   120 = Old Swoop //Debug
            if (CantoAllowsNormalActions(Canto))
            {
                // Skills: Savior
                if (commands.Contains("Rescue") && unit.has_cover() &&
                    !unit.is_rescue_blocked())
                {
                    List <int> allyRange = unit.allies_in_range(1);
                    bool       canRescue = false;
                    foreach (int id in allyRange)
                    {
                        if (unit.can_rescue(Global.game_map.units[id]))
                        {
                            if (Pathfind.passable(unit, Global.game_map.units[id].loc))
                            {
                                canRescue = true;
                                break;
                            }
                        }
                    }
                    if (canRescue)
                    {
                        int index = commands.IndexOf("Rescue");
                        commands.Insert(index + 1, "Shelter");
                        AddSkillIndex(index, SkillMenuIds.Shelter);
                    }
                }
                {
                    List <int> allyRange     = unit.allies_in_range(1);
                    bool       canTakeRefuge = false;
                    foreach (int id in allyRange)
                    {
                        Game_Unit target = Global.game_map.units[id];
                        if (target.has_refuge() && target.can_rescue(unit) &&
                            !unit.is_rescue_blocked())
                        {
                            canTakeRefuge = true;
                            break;
                        }
                    }
                    if (canTakeRefuge)
                    {
                        // Place before status and wait, at least
                        int index = Math.Min(
                            commands.IndexOf("Status"), commands.IndexOf("Wait"));

                        // Try placing before Item
                        int itemIndex = commands.IndexOf("Item");
                        if (itemIndex >= 0)
                        {
                            index = itemIndex;
                        }
                        // Try placing after rescue
                        int rescueIndex = commands.IndexOf("Rescue");
                        if (rescueIndex >= 0)
                        {
                            index = rescueIndex + 1;
                        }
                        // Try placing after shelter
                        int shelterIndex = commands.IndexOf("Shelter");
                        if (shelterIndex >= 0)
                        {
                            index = shelterIndex + 1;
                        }

                        commands.Insert(index + 0, "Refuge");
                        AddSkillIndex(index - 1, SkillMenuIds.Refuge);
                    }
                }
                // Skills: Dash
                if (unit.actor.has_skill("DASH"))
                {
                    // Can move and not in starting location/has done something
                    if (unit.base_mov > 0 && (unit.turn_start_loc != unit.loc ||
                                              Canto != Canto_Records.None))
                    {
                        int index = Math.Min(
                            commands.IndexOf("Status"), commands.IndexOf("Wait"));
                        commands.Insert(index + 0, "Dash");
                        AddSkillIndex(index - 1, SkillMenuIds.Dash);
                    }
                }
                // Skills: Swoop
                if (unit.actor.has_skill("SWOOP"))
                {
                    List <int>[] ary        = unit.enemies_in_swoop_range();
                    List <int>   enemyRange = ary[0];
                    if (enemyRange.Count > 0)
                    {
                        Global.game_temp.temp_skill_ranges["SWOOP"] = unit.swoop_range();
                        Global.game_map.range_start_timer           = 0;
                        int index = commands.IndexOf("Attack");
                        commands.Insert(index + 1, "Swoop");
                        AddSkillIndex(index, SkillMenuIds.Swoop);
                    }
                }
                // Skills: Trample
                if (unit.actor.has_skill("TRAMPLE"))
                {
                    List <int>[] ary        = unit.enemies_in_trample_range();
                    List <int>   enemyRange = ary[0];
                    if (enemyRange.Count > 0)
                    {
                        Global.game_temp.temp_skill_ranges["TRAMPLE"]      = unit.trample_range();
                        Global.game_temp.temp_skill_move_ranges["TRAMPLE"] = unit.trample_move_range();
                        Global.game_map.range_start_timer = 0;
                        int index = commands.IndexOf("Attack");
                        commands.Insert(index + 1, "Trample");
                        AddSkillIndex(index, SkillMenuIds.Trample);
                    }
                }
                // Skills: Sacrifice
                if (unit.actor.has_skill("SACRIFICE"))
                {
                    if (unit.actor.hp > 1)
                    {
                        List <int> allyRange = unit.allies_in_range(1);
                        bool       canHeal   = false;
                        foreach (int id in allyRange)
                        {
                            if (!Global.game_map.units[id].actor.is_full_hp())
                            {
                                canHeal = true;
                                break;
                            }
                        }
                        if (canHeal)
                        {
                            int index = commands.IndexOf("Attack");
                            commands.Insert(index + 1, "Sacrifice");
                            AddSkillIndex(index, SkillMenuIds.Sacrifice);
                        }
                    }
                }
                // Skills: Old Swoop //@Debug
                if (unit.actor.has_skill("OLDSWOOP"))
                {
                    List <int>[] ary        = unit.enemies_in_old_swoop_range();
                    List <int>   enemyRange = ary[0];
                    if (enemyRange.Count > 0)
                    {
                        Global.game_temp.temp_skill_ranges["OLDSWOOP"] = unit.old_swoop_range();
                        Global.game_map.range_start_timer = 0;
                        int index = commands.IndexOf("Attack");
                        commands.Insert(index + 1, "OldSwoop");
                        AddSkillIndex(index, SkillMenuIds.OldSwoop);
                    }
                }
                // Skills: Masteries
                for (int i = 0; i < Game_Unit.MASTERIES.Count; i++)
                {
                    if (unit.actor.has_skill(Game_Unit.MASTERIES[i]) && unit.is_mastery_ready(Game_Unit.MASTERIES[i]))
                    {
                        string       skill    = Game_Unit.MASTERIES[i];
                        List <int>[] rangeAry = unit.enemies_in_range(skill);
                        if (rangeAry[1].Count > 0)
                        {
                            List <int> itemIndices = unit.weapon_indices(rangeAry[1]);
                            Global.game_temp.temp_skill_ranges[skill] = unit.get_weapon_range(itemIndices, new HashSet <Vector2> {
                                unit.loc
                            }, skill);

                            //Global.game_temp.temp_skill_ranges[skill] = Global.game_map.get_unit_range(new List<Vector2> { unit.loc },
                            //    unit.min_range_absolute(skill), unit.max_range_absolute(skill), Game_Unit.mastery_blocked_through_walls(skill));
                            Global.game_map.range_start_timer = 0;

                            int index = commands.IndexOf("Attack");
                            commands.Insert(index + 1, Global.skill_from_abstract(skill).Name);
                            IndexRedirect.Insert(index + 1, BASE_MASTERY_MENU_ID + i);
                        }
                    }
                }
            }
        }