Ejemplo n.º 1
0
        /// <summary>
        /// Bulldoze a tile (River or Dirt)
        ///
        /// TODO: Change X,Y to position
        /// </summary>
        /// <param name="x">X - Where</param>
        /// <param name="y">Y - Where</param>
        /// <param name="effects">Modification Collecting Collection</param>
        /// <returns>Tool Result</returns>
        public ToolResult LayDoze(int x, int y, ToolEffects effects)
        {
            ushort tile = effects.GetMapValue(x, y);

            if ((tile & (ushort)MapTileBits.Bulldozable).IsFalse())
            {
                return(ToolResult.Failed);         /* Check dozeable bit. */
            }

            tile &= (ushort)MapTileBits.LowMask;
            tile  = NeutralizeRoad(tile);

            switch (tile)
            {
            case (ushort)MapTileCharacters.HBRIDGE:
            case (ushort)MapTileCharacters.VBRIDGE:
            case (ushort)MapTileCharacters.BRWV:
            case (ushort)MapTileCharacters.BRWH:
            case (ushort)MapTileCharacters.HBRDG0:
            case (ushort)MapTileCharacters.HBRDG1:
            case (ushort)MapTileCharacters.HBRDG2:
            case (ushort)MapTileCharacters.HBRDG3:
            case (ushort)MapTileCharacters.VBRDG0:
            case (ushort)MapTileCharacters.VBRDG1:
            case (ushort)MapTileCharacters.VBRDG2:
            case (ushort)MapTileCharacters.VBRDG3:
            case (ushort)MapTileCharacters.HPOWER:
            case (ushort)MapTileCharacters.VPOWER:
            case (ushort)MapTileCharacters.HRAIL:
            case (ushort)MapTileCharacters.VRAIL:               /* Dozing over water, replace with water. */
                effects.SetMapValue(x, y, (ushort)MapTileCharacters.RIVER);
                break;

            default:                  /* Dozing on land, replace with land.  Simple, eh? */
                effects.SetMapValue(x, y, (ushort)MapTileCharacters.DIRT);
                break;
            }

            effects.AddCost(1);                     /* Costs $1.00.... */

            return(ToolResult.Ok);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Lay a wire, and update connections (rail, road, and wire) around it.
        ///
        /// TODO: Change X,Y to a position
        /// </summary>
        /// <param name="x">X -Where</param>
        /// <param name="y">Y - Where</param>
        /// <param name="effects">Modification Collecting Collection</param>
        /// <returns>Tool Result</returns>
        public ToolResult LayWire(int x, int y, ToolEffects effects)
        {
            int cost = 5;

            ushort tile = effects.GetMapTile(x, y);

            tile = NeutralizeRoad(tile);

            switch (tile)
            {
            case (ushort)MapTileCharacters.DIRT:                /* Wire on Dirt */

                effects.SetMapValue(x, y, (ushort)MapTileCharacters.LHPOWER | (ushort)MapTileBits.Conductivity | (ushort)MapTileBits.Burnable | (ushort)MapTileBits.Bulldozable);

                break;

            case (ushort)MapTileCharacters.RIVER:               /* Wire on Water */
            case (ushort)MapTileCharacters.REDGE:
            case (ushort)MapTileCharacters.CHANNEL:             /* Check how to lay underwater wire, if possible. */

                cost = 25;

                if (x < Constants.WorldWidth - 1)
                {
                    tile = effects.GetMapValue(x + 1, y);
                    if ((tile & (ushort)MapTileBits.Conductivity).IsTrue())
                    {
                        tile &= (ushort)MapTileBits.LowMask;
                        tile  = NeutralizeRoad(tile);
                        if (tile != (ushort)MapTileCharacters.HROADPOWER && tile != (ushort)MapTileCharacters.RAILHPOWERV && tile != (ushort)MapTileCharacters.HPOWER)
                        {
                            effects.SetMapValue(x, y, (ushort)MapTileCharacters.VPOWER | (ushort)MapTileBits.Conductivity | (ushort)MapTileBits.Bulldozable);
                            break;
                        }
                    }
                }

                if (x > 0)
                {
                    tile = effects.GetMapValue(x - 1, y);
                    if ((tile & (ushort)MapTileBits.Conductivity).IsTrue())
                    {
                        tile &= (ushort)MapTileBits.LowMask;
                        tile  = NeutralizeRoad(tile);
                        if (tile != (ushort)MapTileCharacters.HROADPOWER && tile != (ushort)MapTileCharacters.RAILHPOWERV && tile != (ushort)MapTileCharacters.HPOWER)
                        {
                            effects.SetMapValue(x, y, (ushort)MapTileCharacters.VPOWER | (ushort)MapTileBits.Conductivity | (ushort)MapTileBits.Bulldozable);
                            break;
                        }
                    }
                }

                if (y < Constants.WorldHeight - 1)
                {
                    tile = effects.GetMapValue(x, y + 1);
                    if ((tile & (ushort)MapTileBits.Conductivity).IsTrue())
                    {
                        tile &= (ushort)MapTileBits.LowMask;
                        tile  = NeutralizeRoad(tile);
                        if (tile != (ushort)MapTileCharacters.VROADPOWER && tile != (ushort)MapTileCharacters.RAILVPOWERH && tile != (ushort)MapTileCharacters.VPOWER)
                        {
                            effects.SetMapValue(x, y, (ushort)MapTileCharacters.HPOWER | (ushort)MapTileBits.Conductivity | (ushort)MapTileBits.Bulldozable);
                            break;
                        }
                    }
                }

                if (y > 0)
                {
                    tile = effects.GetMapValue(x, y - 1);
                    if ((tile & (ushort)MapTileBits.Conductivity).IsTrue())
                    {
                        tile &= (ushort)MapTileBits.LowMask;
                        tile  = NeutralizeRoad(tile);
                        if (tile != (ushort)MapTileCharacters.VROADPOWER && tile != (ushort)MapTileCharacters.RAILVPOWERH && tile != (ushort)MapTileCharacters.VPOWER)
                        {
                            effects.SetMapValue(x, y, (ushort)MapTileCharacters.HPOWER | (ushort)MapTileBits.Conductivity | (ushort)MapTileBits.Bulldozable);
                            break;
                        }
                    }
                }

                /* Can't do wire... */
                return(ToolResult.Failed);

            case (ushort)MapTileCharacters.ROADS:                  /* Wire on Road */
                effects.SetMapValue(x, y, (ushort)MapTileCharacters.HROADPOWER | (ushort)MapTileBits.Conductivity | (ushort)MapTileBits.Burnable | (ushort)MapTileBits.Bulldozable);
                break;

            case (ushort)MapTileCharacters.ROADS2:                  /* Wire on Road #2 */
                effects.SetMapValue(x, y, (ushort)MapTileCharacters.VROADPOWER | (ushort)MapTileBits.Conductivity | (ushort)MapTileBits.Burnable | (ushort)MapTileBits.Bulldozable);
                break;

            case (ushort)MapTileCharacters.LHRAIL:                 /* Wire on rail */
                effects.SetMapValue(x, y, (ushort)MapTileCharacters.RAILHPOWERV | (ushort)MapTileBits.Conductivity | (ushort)MapTileBits.Burnable | (ushort)MapTileBits.Bulldozable);
                break;

            case (ushort)MapTileCharacters.LVRAIL:                 /* Wire on rail #2 */
                effects.SetMapValue(x, y, (ushort)MapTileCharacters.RAILVPOWERH | (ushort)MapTileBits.Conductivity | (ushort)MapTileBits.Burnable | (ushort)MapTileBits.Bulldozable);
                break;

            default:                  /* Can't do wire */
                return(ToolResult.Failed);
            }

            effects.AddCost(cost);
            return(ToolResult.Ok);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Lay a rail, update the connections around it
        ///
        /// TODO: Change X,Y to a position
        /// </summary>
        /// <param name="x">X -Where</param>
        /// <param name="y">Y - Where</param>
        /// <param name="effects">Modification Collecting Collection</param>
        /// <returns>Tool Result</returns>
        public ToolResult LayRail(int x, int y, ToolEffects effects)
        {
            int cost = 20;

            ushort tile = effects.GetMapTile(x, y);

            tile = NeutralizeRoad(tile);

            switch (tile)
            {
            case (ushort)MapTileCharacters.DIRT:                       /* Rail on Dirt */

                effects.SetMapValue(x, y, (ushort)MapTileCharacters.LHRAIL | (ushort)MapTileBits.Bulldozable | (ushort)MapTileBits.Burnable);

                break;

            case (ushort)MapTileCharacters.RIVER:          /* Rail on Water */
            case (ushort)MapTileCharacters.REDGE:
            case (ushort)MapTileCharacters.CHANNEL:        /* Check how to build underwater tunnel, if possible. */

                cost = 100;

                if (x < Constants.WorldWidth - 1)
                {
                    tile = effects.GetMapTile(x + 1, y);
                    tile = NeutralizeRoad(tile);
                    if (tile == (ushort)MapTileCharacters.RAILHPOWERV || tile == (ushort)MapTileCharacters.HRAIL ||
                        (tile >= (ushort)MapTileCharacters.LHRAIL && tile <= (ushort)MapTileCharacters.HRAILROAD))
                    {
                        effects.SetMapValue(x, y, (ushort)MapTileCharacters.HRAIL | (ushort)MapTileBits.Bulldozable);
                        break;
                    }
                }

                if (x > 0)
                {
                    tile = effects.GetMapTile(x - 1, y);
                    tile = NeutralizeRoad(tile);
                    if (tile == (ushort)MapTileCharacters.RAILHPOWERV || tile == (ushort)MapTileCharacters.HRAIL ||
                        (tile > (ushort)MapTileCharacters.VRAIL && tile < (ushort)MapTileCharacters.VRAILROAD))
                    {
                        effects.SetMapValue(x, y, (ushort)MapTileCharacters.HRAIL | (ushort)MapTileBits.Bulldozable);
                        break;
                    }
                }

                if (y < Constants.WorldHeight - 1)
                {
                    tile = effects.GetMapTile(x, y + 1);
                    tile = NeutralizeRoad(tile);
                    if (tile == (ushort)MapTileCharacters.RAILVPOWERH || tile == (ushort)MapTileCharacters.VRAILROAD ||
                        (tile > (ushort)MapTileCharacters.HRAIL && tile < (ushort)MapTileCharacters.HRAILROAD))
                    {
                        effects.SetMapValue(x, y, (ushort)MapTileCharacters.VRAIL | (ushort)MapTileBits.Bulldozable);
                        break;
                    }
                }

                if (y > 0)
                {
                    tile = effects.GetMapTile(x, y - 1);
                    tile = NeutralizeRoad(tile);
                    if (tile == (ushort)MapTileCharacters.RAILVPOWERH || tile == (ushort)MapTileCharacters.VRAILROAD ||
                        (tile > (ushort)MapTileCharacters.HRAIL && tile < (ushort)MapTileCharacters.HRAILROAD))
                    {
                        effects.SetMapValue(x, y, (ushort)MapTileCharacters.VRAIL | (ushort)MapTileBits.Bulldozable);
                        break;
                    }
                }

                /* Can't do rail... */
                return(ToolResult.Failed);

            case (ushort)MapTileCharacters.LHPOWER:                 /* Rail on power */
                effects.SetMapValue(x, y, (ushort)MapTileCharacters.RAILVPOWERH | (ushort)MapTileBits.Conductivity | (ushort)MapTileBits.Burnable | (ushort)MapTileBits.Bulldozable);
                break;

            case (ushort)MapTileCharacters.LVPOWER:                 /* Rail on power #2 */
                effects.SetMapValue(x, y, (ushort)MapTileCharacters.RAILHPOWERV | (ushort)MapTileBits.Conductivity | (ushort)MapTileBits.Burnable | (ushort)MapTileBits.Bulldozable);
                break;

            case (ushort)MapTileCharacters.ROADS:                  /* Rail on road */
                effects.SetMapValue(x, y, (ushort)MapTileCharacters.VRAILROAD | (ushort)MapTileBits.Burnable | (ushort)MapTileBits.Bulldozable);
                break;

            case (ushort)MapTileCharacters.ROADS2:                  /* Rail on road #2 */
                effects.SetMapValue(x, y, (ushort)MapTileCharacters.HRAILROAD | (ushort)MapTileBits.Burnable | (ushort)MapTileBits.Bulldozable);
                break;

            default:                  /* Can't do rail */
                return(ToolResult.Failed);
            }

            effects.AddCost(cost);
            return(ToolResult.Ok);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Lay a road, and update the road around it
        ///
        /// TODO: Change X,Y to a position
        /// </summary>
        /// <param name="x">X - Where</param>
        /// <param name="y">Y - Where</param>
        /// <param name="effects">Modification Collecting Collection</param>
        /// <returns>Tool Result</returns>
        public ToolResult LayRoad(int x, int y, ToolEffects effects)
        {
            int cost = 10;

            ushort tile = effects.GetMapTile(x, y);

            switch (tile)
            {
            case (ushort)MapTileCharacters.DIRT:
                effects.SetMapValue(x, y, (ushort)MapTileCharacters.ROADS | (ushort)MapTileBits.Bulldozable | (ushort)MapTileBits.Burnable);
                break;

            case (ushort)MapTileCharacters.RIVER:                       /* Road on Water */
            case (ushort)MapTileCharacters.REDGE:
            case (ushort)MapTileCharacters.CHANNEL:                     /* Check how to build bridges, if possible. */
                cost = 50;

                if (x < Constants.WorldWidth - 1)
                {
                    tile = effects.GetMapTile(x + 1, y);
                    tile = NeutralizeRoad(tile);
                    if (tile == (ushort)MapTileCharacters.VRAILROAD || tile == (ushort)MapTileCharacters.HBRIDGE ||
                        (tile >= (ushort)MapTileCharacters.ROADS && tile <= (ushort)MapTileCharacters.HROADPOWER))
                    {
                        effects.SetMapValue(x, y, (ushort)MapTileCharacters.HBRIDGE | (ushort)MapTileBits.Bulldozable);
                        break;
                    }
                }

                if (x > 0)
                {
                    tile = effects.GetMapTile(x - 1, y);
                    tile = NeutralizeRoad(tile);
                    if (tile == (ushort)MapTileCharacters.VRAILROAD || tile == (ushort)MapTileCharacters.HBRIDGE ||
                        (tile >= (ushort)MapTileCharacters.ROADS && tile <= (ushort)MapTileCharacters.INTERSECTION))
                    {
                        effects.SetMapValue(x, y, (ushort)MapTileCharacters.HBRIDGE | (ushort)MapTileBits.Bulldozable);
                        break;
                    }
                }

                if (y < Constants.WorldHeight - 1)
                {
                    tile = effects.GetMapTile(x, y + 1);
                    tile = NeutralizeRoad(tile);
                    if (tile == (ushort)MapTileCharacters.HRAILROAD || tile == (ushort)MapTileCharacters.VROADPOWER ||
                        (tile >= (ushort)MapTileCharacters.VBRIDGE && tile <= (ushort)MapTileCharacters.INTERSECTION))
                    {
                        effects.SetMapValue(x, y, (ushort)MapTileCharacters.VBRIDGE | (ushort)MapTileBits.Bulldozable);
                        break;
                    }
                }

                if (y > 0)
                {
                    tile = effects.GetMapTile(x, y - 1);
                    tile = NeutralizeRoad(tile);
                    if (tile == (ushort)MapTileCharacters.HRAILROAD || tile == (ushort)MapTileCharacters.VROADPOWER ||
                        (tile >= (ushort)MapTileCharacters.VBRIDGE && tile <= (ushort)MapTileCharacters.INTERSECTION))
                    {
                        effects.SetMapValue(x, y, (ushort)MapTileCharacters.VBRIDGE | (ushort)MapTileBits.Bulldozable);
                        break;
                    }
                }

                /* Can't do road... */
                return(ToolResult.Failed);

            case (ushort)MapTileCharacters.LHPOWER:             /* Road on power */
                effects.SetMapValue(x, y, (ushort)MapTileCharacters.VROADPOWER | (ushort)MapTileBits.Conductivity | (ushort)MapTileBits.Burnable | (ushort)MapTileBits.Bulldozable);
                break;

            case (ushort)MapTileCharacters.LVPOWER:             /* Road on power #2 */
                effects.SetMapValue(x, y, (ushort)MapTileCharacters.HROADPOWER | (ushort)MapTileBits.Conductivity | (ushort)MapTileBits.Burnable | (ushort)MapTileBits.Bulldozable);
                break;

            case (ushort)MapTileCharacters.LHRAIL:              /* Road on rail */
                effects.SetMapValue(x, y, (ushort)MapTileCharacters.HRAILROAD | (ushort)MapTileBits.Burnable | (ushort)MapTileBits.Bulldozable);
                break;

            case (ushort)MapTileCharacters.LVRAIL:              /* Road on rail #2 */
                effects.SetMapValue(x, y, (ushort)MapTileCharacters.VRAILROAD | (ushort)MapTileBits.Burnable | (ushort)MapTileBits.Bulldozable);
                break;

            default:                  /* Can't do road */
                return(ToolResult.Failed);
            }

            effects.AddCost(cost);
            return(ToolResult.Ok);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Perform the command, and fix wire/road/rail/zone connections around it.
        ///
        /// Store modification in the \a effects object.
        ///
        /// TODO: Change X,Y to position
        /// </summary>
        /// <param name="x">X - Where to perform the command</param>
        /// <param name="y">Y - Where to perform the command</param>
        /// <param name="cmd">Command to perform</param>
        /// <param name="effects">Modification collecting Objects</param>
        /// <returns>The result</returns>
        public ToolResult ConnectTile(int x, int y, ConnectTileCommand cmd, ToolEffects effects)
        {
            ToolResult result = ToolResult.Ok;

            // Make sure the array subscripts are in bounds.
            if (!Position.TestBounds(x, y))
            {
                return(ToolResult.Failed);
            }

            // Perform auto-doze if appropriate.
            switch (cmd)
            {
            case ConnectTileCommand.Road:
            case ConnectTileCommand.RailRoad:
            case ConnectTileCommand.Wire:

                // Silently skip auto-bulldoze if no money.
                if (AutoBulldoze)
                {
                    ushort mapVal = effects.GetMapValue(x, y);

                    if ((mapVal & (ushort)MapTileBits.Bulldozable).IsTrue())
                    {
                        mapVal &= (ushort)MapTileBits.LowMask;
                        mapVal  = NeutralizeRoad(mapVal);

                        /* Maybe this should check BULLBIT instead of checking tile values? */
                        if ((mapVal >= (ushort)MapTileCharacters.TINYEXP && mapVal <= (ushort)MapTileCharacters.LASTTINYEXP) ||
                            (mapVal < (ushort)MapTileCharacters.HBRIDGE && mapVal != (ushort)MapTileCharacters.DIRT))
                        {
                            effects.AddCost(1);

                            effects.SetMapValue(x, y, (ushort)MapTileCharacters.DIRT);
                        }
                    }
                }
                break;

            default:
                // Do nothing.
                break;
            }

            // Perform the command.
            switch (cmd)
            {
            case ConnectTileCommand.Fix:     // Fix zone.
                FixZone(x, y, effects);
                break;

            case ConnectTileCommand.Bulldoze:     // Bulldoze zone.
                result = LayDoze(x, y, effects);
                FixZone(x, y, effects);
                break;

            case ConnectTileCommand.Road:     // Lay road.
                result = LayRoad(x, y, effects);
                FixZone(x, y, effects);
                break;

            case ConnectTileCommand.RailRoad:     // Lay railroad.
                result = LayRail(x, y, effects);
                FixZone(x, y, effects);
                break;

            case ConnectTileCommand.Wire:     // Lay wire.
                result = LayWire(x, y, effects);
                FixZone(x, y, effects);
                break;

            default:
                //Do Nothing
                break;
            }

            return(result);
        }