Ejemplo n.º 1
0
 public virtual void move(String movestring, MovestringEndingDelegate callback, int timeout)
 {
     this.movestring = new Movestring(movestring, callback, this, timeout);
 }
Ejemplo n.º 2
0
        public Movestring(String movestring, MovestringEndingDelegate callback, Entity e, int timeout)
        {
            ent = e;
            if (callback != null) on_done += callback;
            this.timeout = timeout;

            MatchCollection matches = regex.Matches(movestring);
            GroupCollection groups;
            Queue<MovestringCommand> command_queue = new Queue<MovestringCommand>();
            Queue<int> param_queue = new Queue<int>();

            restart();

            if (String.IsNullOrEmpty(movestring)) {
                commands = new MovestringCommand[1];
                parameters = new int[1];
                commands[0] = MovestringCommand.Stop;
                parameters[0] = NO_NUMBER;
                stop(false);
                return;
            }

            MovestringCommand command;
            int parameter;
            bool open_ended = true;
            bool time_consuming = false;

            foreach (Match match in matches) {
                groups = match.Groups;
                parameter = NO_NUMBER;
                if (!String.IsNullOrEmpty(groups[2].Value)) parameter = Int32.Parse(groups[2].Value);
                param_queue.Enqueue(parameter);

                // WHO HERE LIKES HUGE SWITCHES? YEAH!!
                switch (groups[1].Value) {
                    case "B": // loop back to start.
                        // This normally takes no number parameter, but unlike VERGE, you can include one, in which case
                        // it will loop that many times, then stop.
                        if (!time_consuming) {
                            command = MovestringCommand.Stop; // sanity check against inescapable processing loop
                            parameter = NO_NUMBER;
                        }
                        else command = MovestringCommand.Loop;
                        open_ended = false;
                        break;
                    case "T": // switch to pixel coordinates
                        command = MovestringCommand.TileMode;
                        break;
                    case "P": // switch to tile coordinates
                        command = MovestringCommand.PixelMode;
                        break;
                    case "Z": // frame switch (may or may not have a number parameter)
                        // This locks the entity into the specified frame, suppressing animation during movement. In VERGE, setting it to 0
                        // restored the entity to normal animation, but this is a problem if you want to lock it at frame 0. Thus, I'm changing
                        // the rule: Z0 locks the entity at frame 0, and Z with no number after it restores normal animation.
                        // Be warned that this may mess up the occasional .MAP-embedded movestring.
                        command = MovestringCommand.Frame;
                        break;
                    case "F": // face (not necessary, since a distance-0 move accomplishes the same thing)
                        command = MovestringCommand.Face;
                        break;
                    case "U": // move up
                        command = MovestringCommand.Up;
                        time_consuming = true;
                        break;
                    case "D": // move down
                        command = MovestringCommand.Down;
                        time_consuming = true;
                        break;
                    case "L": // move left
                        command = MovestringCommand.Left;
                        time_consuming = true;
                        break;
                    case "R": // move right
                        command = MovestringCommand.Right;
                        time_consuming = true;
                        break;
                    case "W": // wait
                        command = MovestringCommand.Wait;
                        time_consuming = true;
                        break;
                    case "X": // walk straight to specific x
                        command = MovestringCommand.ToX;
                        time_consuming = true;
                        break;
                    case "Y": // walk straight to specific y
                        command = MovestringCommand.ToY;
                        time_consuming = true;
                        break;
                    default: throw new MalformedMovestringException(movestring);
                }
                command_queue.Enqueue(command);
            }

            if (open_ended) {
                command_queue.Enqueue(MovestringCommand.Stop);
                param_queue.Enqueue(Movestring.NO_NUMBER);
            }

            commands = new MovestringCommand[command_queue.Count];
            parameters = new int[commands.Length];

            for (int i = 0; i < commands.Length; i++) {
                commands[i] = command_queue.Dequeue();
                parameters[i] = param_queue.Dequeue();
            }
        }
Ejemplo n.º 3
0
 public virtual void move(String movestring, MovestringEndingDelegate callback)
 {
     this.move(movestring, callback, Movestring.NEVER_TIMEOUT);
 }
Ejemplo n.º 4
0
 public Movestring(String movestring, MovestringEndingDelegate callback, Entity e)
     : this(movestring, callback, e, NEVER_TIMEOUT)
 {
 }