// Constructor
 public PrioritizedCommand(Commands.Command newCommand)
 {
     /*if (newCommand.GetType() == typeof(Tests.DynamicDamageCommand))
     {
         damage = ((Tests.DynamicDamageCommand)newCommand).Strength;
     }
     else*/ if (newCommand.GetType() == typeof(Commands.DamageCommand))
     {
         damage = ((Commands.DamageCommand)newCommand).Strength;
     }
     range = newCommand.Range;
     command = newCommand;
     next = null;
     targetOptions = new List<CommandInfo>();
 }
Esempio n. 2
0
        // Fills a PrioritizedCommand object with a list of all the valid nodes from which a program can execute the
        // associated command.  This list will be used by the AI in conjunction with AStar pathfinding to determine
        // the best node to move to and issue a command from this turn.
        private PrioritizedCommand FindCommandOptions(Haxxit.Maps.ProgramHeadNode program, Commands.Command command)
        {
            PrioritizedCommand newPrioritizedCommand = new PrioritizedCommand(command);

            // For every enemy program...
            foreach (Haxxit.Maps.ProgramHeadNode enemyProgram in enemyPrograms)
            {
                // For every node in that enemy program...
                foreach (Haxxit.Maps.ProgramNode node in enemyProgram.GetAllNodes())
                {
                    List<Haxxit.Maps.Point> commandPoints = new List<Haxxit.Maps.Point>();

                    // Remember that GetAllNodes is from Haxxit.Maps, which is unaware of pending changes in mapData here.
                    // Second check is necessary in the extremely rare event that friendly programs have both eliminated the enemy program node here and expanded into it themselves earlier this turn.
                    if (mapData[node.coordinate.X, node.coordinate.Y].OccupiedBy != null && mapData[node.coordinate.X, node.coordinate.Y].OccupiedBy.Program == enemyProgram.Program)
                    {
                        commandPoints = FindNodesInRange(program, node.coordinate, newPrioritizedCommand.Range);
                    }

                    // For every point in range of that node in the enemy program...
                    foreach (Haxxit.Maps.Point point in commandPoints)
                    {
                        // Attempt to find a path to that point
                        Stack<Haxxit.Maps.Point> path = AStar(program, point);
                        if (path != null)
                        {
                            // Record the shortest path to that point as well as the command and target information
                            CommandInfo newCommandInfo = new CommandInfo(point, node.coordinate, enemyProgram, path);
                            newPrioritizedCommand.TargetOptions.Add(newCommandInfo);
                        }
                    }
                }
            }

            // Sort the different usage options for this command by the length of the path required to use them.
            // The CommandInfo class has an internal comparable interface for performing this sort.
            newPrioritizedCommand.TargetOptions.Sort();
            return newPrioritizedCommand;
        }