Exemplo n.º 1
0
        public override RobotState Update(RobotState state, float dt)
        {
            var timer = state.Level.TimeMachine.Time - state.TimeStamp;

            if (timer >= DURATION && state.Position.Y > state.Level.Tiles.MinY - 2)
            {
                var below      = state.Position.Below();
                var belowBelow = below.Below();
                if (state.Level.Tiles[belowBelow].IsLiquid(state.Level, belowBelow))
                {
                    return(RobotActions.Drown.Init(state.With(position: below)));
                }
                else if (state.Level.Tiles[belowBelow].CanEnterOnTop(state.Level, belowBelow))
                {
                    return(RobotActions.Fall.Init(state.With(position: below)));
                }
                else
                {
                    state.Level.Tiles[belowBelow].OnSteppedOn(state.Level, belowBelow, state.Robot, state.Direction);
                    return(PickNextAction(state.With(position: below), allowTeleport: true, allowTurntable: true));
                }
            }
            else
            {
                return(state);
            }
        }
Exemplo n.º 2
0
        public override RobotState Update(RobotState state, float dt)
        {
            float newTimer = state.Level.TimeMachine.Time - state.TimeStamp;

            if (newTimer >= DURATION)
            {
                return(PickNextAction(state.With(position: GetDestination(state))));
            }
            else
            {
                return(state);
            }
        }
Exemplo n.º 3
0
        public override RobotState Update(RobotState state, float dt)
        {
            var timer = state.Level.TimeMachine.Time - state.TimeStamp;

            if (timer >= DURATION)
            {
                var newPosition = GetDestination(state);
                return(RobotActions.Drowned.Init(state.With(position: newPosition)));
            }
            else
            {
                return(state);
            }
        }
Exemplo n.º 4
0
        public override RobotState Update(RobotState state, float dt)
        {
            var newTimer = state.Level.TimeMachine.Time - state.TimeStamp;

            if (newTimer >= DURATION)
            {
                var newDirection = state.Direction.Rotate(m_turnDirection);
                var canProceed   = CanEnter(state.Robot, state.Position.Move(newDirection), newDirection, false);
                return(PickNextAction(state.With(direction: newDirection), allowTurntable: !canProceed));
            }
            else
            {
                return(state);
            }
        }
Exemplo n.º 5
0
        public override RobotState Update(RobotState state, float dt)
        {
            float timeInState = state.Level.TimeMachine.Time - state.TimeStamp;

            if (timeInState >= DURATION)
            {
                var destination = GetDestination(state);
                var below       = state.Position.Below();
                state.Level.Tiles[below].OnSteppedOff(state.Level, below, state.Robot, m_direction);
                return(PickNextAction(state.With(position: destination), allowTeleport: true, allowTurntable: true));
            }
            else
            {
                return(state);
            }
        }
Exemplo n.º 6
0
        public override RobotState Update(RobotState state, float dt)
        {
            var newTimer = state.Level.TimeMachine.Time - state.TimeStamp;

            if (newTimer >= DURATION)
            {
                var newDirection = state.Direction.Rotate(m_turnDirection);
                var canProceed   = CanEnter(state.Robot, state.Position.Move(newDirection), newDirection, false);
                var newState     = PickNextAction(state.With(direction: newDirection), allowTurntable: !canProceed);
                if (!(newState.Action is RobotWalkAction || newState.Action is RobotTurnAction || newState.Action is RobotUTurnAction))
                {
                    state.Robot.StopSound("idle_loop");
                }
                return(newState);
            }
            else
            {
                return(state);
            }
        }
Exemplo n.º 7
0
        public override RobotState Update(RobotState state, float dt)
        {
            float newTimer = state.Level.TimeMachine.Time - state.TimeStamp;

            if (newTimer >= DURATION)
            {
                var destination = GetDestination(state);
                var below       = state.Position.Below();
                state.Level.Tiles[below].OnSteppedOff(state.Level, below, state.Robot, state.Direction);
                var newState = PickNextAction(state.With(position: destination), allowTeleport: true, allowTurntable: true);
                if (!(newState.Action is RobotWalkAction || newState.Action is RobotTurnAction || newState.Action is RobotUTurnAction))
                {
                    state.Robot.StopSound("idle_loop");
                }
                return(newState);
            }
            else
            {
                return(state);
            }
        }
Exemplo n.º 8
0
        private static RobotAction NextAction(RobotState state, bool allowTeleport = false, bool allowTurntable = false, bool ignoreMovingObjects = false)
        {
            var level    = state.Level;
            var position = state.Position;
            var below    = position.Below();
            var dir      = state.Direction;

            var currentTile = level.Tiles[position];
            var belowTile   = level.Tiles[below];

            // Try drowning
            if (belowTile.IsLiquid(level, below))
            {
                return(RobotActions.Drown);
            }

            // Try falling
            if (belowTile.CanEnterOnTop(level, below))
            {
                return(RobotActions.Fall);
            }

            // Try sitting at goal
            if (currentTile.IsGoal(level, position))
            {
                var colour = ((GoalTileBehaviour)currentTile.GetBehaviour(level, position)).Colour;
                if (colour == state.Robot.Colour)
                {
                    return(RobotActions.Goal);
                }
            }

            // Try teleporting
            if (allowTeleport && belowTile.IsTelepad(level, below))
            {
                var basePos     = belowTile.GetBase(level, below);
                var baseTile    = level.Tiles[basePos];
                var destination = ((TelepadTileBehaviour)baseTile.GetBehaviour(level, basePos)).GetDestination(level, basePos);
                if (destination.HasValue)
                {
                    return(RobotActions.TeleportOut);
                }
            }

            // Try conveying
            if (belowTile.IsConveyor(level, below))
            {
                var conveyor          = ((Conveyor)belowTile.GetEntity(level, below));
                var conveyorDirection = belowTile.GetDirection(level, below);
                if (conveyor.CurrentMode == ConveyorMode.Forwards)
                {
                    var conveyDirection = conveyorDirection;
                    if (CanEnter(state.Robot, position.Move(conveyDirection), conveyDirection, false))
                    {
                        return(RobotActions.GetConvey(conveyDirection));
                    }
                }
                else if (conveyor.CurrentMode == ConveyorMode.Reverse)
                {
                    var conveyDirection = conveyorDirection.Opposite();
                    if (CanEnter(state.Robot, position.Move(conveyDirection), conveyDirection, false))
                    {
                        return(RobotActions.GetConvey(conveyDirection));
                    }
                }
            }

            // Try turntabling
            if (allowTurntable && currentTile.IsTurntable(level, position))
            {
                var turn = ((TurntableTileBehaviour)currentTile.GetBehaviour(level, position)).TurnDirection;
                switch (turn)
                {
                case TurnDirection.Left:
                {
                    return(RobotActions.TurntableLeft);
                }

                case TurnDirection.Right:
                {
                    return(RobotActions.TurntableRight);
                }
                }
            }

            // Try moving
            if (!state.Robot.Immobile)
            {
                if (CanEnter(state.Robot, position.Move(dir), dir, ignoreMovingObjects))
                {
                    // Walk forward
                    int           incline         = GetWalkIncline(state.Robot, state.Position, state.Direction);
                    var           nextPos         = position.Move(dir.GetX(), incline, dir.GetZ());
                    var           nextAction      = NextAction(state.With(action: RobotActions.WalkLookForward, position: nextPos), allowTeleport: true, allowTurntable: true, ignoreMovingObjects: true);
                    TurnDirection?previousLookDir = null;
                    if (state.Action is RobotWalkAction)
                    {
                        previousLookDir = ((RobotWalkAction)state.Action).LookDirection;
                    }
                    if (nextAction is RobotTurnAction)
                    {
                        var turnAction = (RobotTurnAction)nextAction;
                        return(RobotActions.GetWalk(previousLookDir, turnAction.Direction));
                    }
                    else if (nextAction is RobotUTurnAction)
                    {
                        var turnAction = (RobotUTurnAction)nextAction;
                        return(RobotActions.GetWalk(previousLookDir, turnAction.Direction));
                    }
                    else
                    {
                        return(RobotActions.GetWalk(previousLookDir, null));
                    }
                }
                else
                {
                    // Turn
                    TurnDirection?lookDir = null;
                    if (state.Action is RobotWalkAction)
                    {
                        lookDir = ((RobotWalkAction)state.Action).LookDirection;
                    }

                    bool uTurn;
                    var  turn = GetTurnDirection(state.Robot, position, dir, state.TurnPreference, out uTurn, false);
                    if (uTurn)
                    {
                        return(RobotActions.GetUTurn(turn, lookDir));
                    }
                    else
                    {
                        return(RobotActions.GetTurn(turn, lookDir));
                    }
                }
            }

            // Wait
            return(RobotActions.Wait);
        }
Exemplo n.º 9
0
 public virtual RobotState Init(RobotState state)
 {
     return(state.With(action: this, timeStamp: state.Robot.Level.TimeMachine.Time));
 }