Exemple #1
0
 public Limo(BoardLocation location, Bitmap limoBitmap)
 {
     Location = new BoardLocation(location);
     VehicleBitmap = limoBitmap;
     PathTiles = new List<Point>();
     TailMap = new Queue<Point>();
     TailQuarter = new List<Point>();
     Future = new List<QuarterSteps>();
     vehicleRotated = new Dictionary<int, Bitmap>();
     vehicleRotated[0] = limoBitmap;
 }
Exemple #2
0
 /// <summary>
 /// Copy constructor.
 /// </summary>
 /// <param name="src">Initialize with the values in this struct.</param>
 public BoardLocation(BoardLocation src)
 {
     mapPosition = new Point(src.MapPosition.X, src.MapPosition.Y);
     TileMoves = src.TileMoves;
     OffsetTileMoves = src.OffsetTileMoves;
 }
Exemple #3
0
 public void SetTileLocation(MapSquare square, Point ptTile, MapSquare.COMPASS_DIRECTION direction)
 {
     switch (square.Tile.Direction)
     {
         case MapTile.DIRECTION.NORTH_SOUTH:
         case MapTile.DIRECTION.EAST_WEST:
         case MapTile.DIRECTION.INTERSECTION:
         case MapTile.DIRECTION.T_NORTH:
         case MapTile.DIRECTION.T_EAST:
         case MapTile.DIRECTION.T_SOUTH:
         case MapTile.DIRECTION.T_WEST:
             switch (direction)
             {
                 case MapSquare.COMPASS_DIRECTION.NORTH:
                     Location =
                         new BoardLocation(new Point(ptTile.X*TileMovement.UNITS_PER_TILE + addMiddleFarLane,
                                                     ptTile.Y*TileMovement.UNITS_PER_TILE + addMiddleTile),
                                           TileMovement.GetMove(MapSquare.COMPASS_DIRECTION.NORTH, MapSquare.COMPASS_DIRECTION.NORTH));
                     return;
                 case MapSquare.COMPASS_DIRECTION.EAST:
                     Location =
                         new BoardLocation(new Point(ptTile.X*TileMovement.UNITS_PER_TILE + addMiddleTile,
                                                     ptTile.Y*TileMovement.UNITS_PER_TILE + addMiddleFarLane),
                                           TileMovement.GetMove(MapSquare.COMPASS_DIRECTION.EAST, MapSquare.COMPASS_DIRECTION.EAST));
                     return;
             case MapSquare.COMPASS_DIRECTION.SOUTH:
                     Location = new BoardLocation(new Point(ptTile.X*TileMovement.UNITS_PER_TILE + addMiddleNearLane,
                                                            ptTile.Y*TileMovement.UNITS_PER_TILE + addMiddleTile),
                                                  TileMovement.GetMove(MapSquare.COMPASS_DIRECTION.SOUTH,
                                                                       MapSquare.COMPASS_DIRECTION.SOUTH));
                     return;
             case MapSquare.COMPASS_DIRECTION.WEST:
                     Location = new BoardLocation(new Point(ptTile.X * TileMovement.UNITS_PER_TILE + addMiddleTile,
                                                (ptTile.Y * TileMovement.UNITS_PER_TILE + addMiddleNearLane)),
                                      TileMovement.GetMove(MapSquare.COMPASS_DIRECTION.WEST,
                                                           MapSquare.COMPASS_DIRECTION.WEST));
                     return;
             }
             return;
     }
 }
Exemple #4
0
        /// <summary>
        /// Calculates the estimated path for each limo. Resets count of steps taken. Adjusts speed.
        /// </summary>
        /// <param name="plyr">The player being reset for the move.</param>
        private void PrepareToMove(Player plyr)
        {
            if (log.IsDebugEnabled)
                log.Debug(string.Format("{0} : PrepareToMove, location = {1}", plyr.Name, plyr.Limo.Location));

            plyr.Limo.Future.Clear();
            Point ptOn = plyr.Limo.Location.MapPosition;
            Point ptMapStart = BoardLocation.MapToTile(ptOn);
            plyr.Limo.AddFuture(ptOn);
            BoardLocation location = new BoardLocation(plyr.Limo.Location);
            int pathOffset = 0;

            for (int ind = 0; ind < Limo.NUM_FUTURE; ind++)
            {
                if (location.IsMoveInsideTile)
                {
                    location.Move();
                    plyr.Limo.AddFuture(location.MapPosition);
                    continue;
                }

                // get where we enter the next tile
                Point ptNextMap = location.NextPosition;
                Point ptNextTile = location.NextTilePosition;
                MapSquare squareNext = MainMap.Squares[ptNextTile.X][ptNextTile.Y];
                MapSquare.COMPASS_DIRECTION dirOn = location.Direction;

                // if we enter a stop or signal, we're done guessing the future. We've actually moved the car half way into the
                // intersection in this case. But it's more efficient than getting the front location each step and
                // we need the path up to the tile edge.
                // We go on a signal regardless of color because it can be green when we get there and this is used to see if cars
                // the other way can turn left.
                if (ptNextTile != ptMapStart)
                {
                    if (squareNext.IsStopAllGreen(dirOn))
                    {
                        if (log.IsDebugEnabled)
                            log.Debug(string.Format("{0} : PrepareToMove hit stop at = {1}, {2}", plyr.Name, ptNextTile, dirOn));
                        break;
                    }
                    // might be a u-turn
                    ptMapStart = Point.Empty;
                }

                // move into the next tile - so below calculations are based on the tile we've just entered (but can now move through in any direction).
                location.Move();
                plyr.Limo.AddFuture(location.MapPosition);

                // we now work with the next position because that moves us into the next tile if we are at offset 0 and going north or west.
                // this has to be the next map position converted to tile position because that is sometimes this tile position, sometimes next.
                Trap.trap(location.MapPosition != ptNextMap);
                ptNextMap = location.NextPosition;
                ptNextTile = BoardLocation.MapToTile(ptNextMap);

                // we increment it here because a U-turn does not move to the next tile and we need the same offset again.
                if ((pathOffset < plyr.Limo.PathTiles.Count) && (plyr.Limo.PathTiles[pathOffset] == ptNextTile))
                    pathOffset++;

                // get our new destination - from the path if valid
                MapSquare.COMPASS_DIRECTION destDirection = MapSquare.COMPASS_DIRECTION.NONE;
                if (plyr.Limo.PathTiles.Count > pathOffset)
                {
                    int x = plyr.Limo.PathTiles[pathOffset].X - ptNextTile.X;
                    int y = plyr.Limo.PathTiles[pathOffset].Y - ptNextTile.Y;
                    if (Math.Abs(x) + Math.Abs(y) == 1)
                        destDirection = MapSquare.PointsDirection(ptNextTile, plyr.Limo.PathTiles[pathOffset]);
                    else
                        if (log.IsDebugEnabled)
                            log.Debug(string.Format("{0} : PrepareToMove path error at = {1}, {2}; pathOff={3}, count={4}; x={5}, y={6}", plyr.Name, ptNextTile, dirOn, pathOffset, plyr.Limo.PathTiles.Count, x, y));
                }

                // if no path, we get the next one only if just one choice (straight/curves) or straight is allowed.
                // in other words, entering the top of a T we assume straight across. Entering from the base we stop (returns NONE).
                if (destDirection == MapSquare.COMPASS_DIRECTION.NONE)
                    destDirection = squareNext.Tile.GetStraightNext(dirOn);
                if (destDirection == MapSquare.COMPASS_DIRECTION.NONE)
                {
                    if (log.IsDebugEnabled)
                        log.Debug(string.Format("{0} : PrepareToMove no dirNext at = {1}, {2}; pathOff={3}, count={4}", plyr.Name, ptNextTile, dirOn, pathOffset, plyr.Limo.PathTiles.Count));
                    break;
                }

                // get the inter-tile movement and assign
                TileMovement movement = TileMovement.GetMove(dirOn, destDirection);
                location.SetMapPosition(location.MapPosition, movement);
                if (log.IsDebugEnabled)
                    log.Debug(string.Format("{0} : PrepareToMove next tile complete, location = {1}", plyr.Name, location));
            }

            if (log.IsDebugEnabled)
            {
                if (plyr.Limo.Future.Count == 0)
                    log.Debug(string.Format("{0} : PrepareToMove complete, future, len=0", plyr.Name));
                else
                    log.Debug(string.Format("{0} : PrepareToMove complete, future = {1}..{2}, len={3}", plyr.Name,
                                        plyr.Limo.Future[0], plyr.Limo.Future[plyr.Limo.Future.Count - 1], plyr.Limo.Future.Count));
            }
        }