Esempio n. 1
0
        /// <summary>
        /// Temporary function to prevent breaking a lot of code.
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="preserve"></param>
        private void smoothTreesAt(int x, int y, bool preserve)
        {
            var effects = new ToolEffects(this);

            smoothTreesAt(x, y, preserve, effects);
            effects.modifyWorld();
        }
        /// <summary>
        /// Temporary function to prevent breaking a lot of code.
        ///
        /// TODO: Change X,Y for Position
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="preserve"></param>
        private void SmoothTreesAt(int x, int y, bool preserve)
        {
            ToolEffects effects = new ToolEffects(this);

            SmoothTreesAt(x, y, preserve, effects);
            effects.ModifyWorld();
        }
Esempio n. 3
0
        /// <summary>
        /// Smooth trees at a position
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="preserve"></param>
        /// <param name="effects"></param>
        private void smoothTreesAt(int x, int y, bool preserve, ToolEffects effects)
        {
            short[] dx        = { -1, 0, 1, 0 };
            short[] dy        = { 0, 1, 0, -1 };
            short[] treeTable =
            {
                0,   0,  0, 34,
                0,   0, 36, 35,
                0,  32,  0, 33,
                30, 31, 29, 37,
            };

            if (!isTree(effects.getMapValue(x, y)))
            {
                return;
            }

            int bitIndex = 0;
            int z;

            for (z = 0; z < 4; z++)
            {
                bitIndex = bitIndex << 1;
                int xTemp = x + dx[z];
                int yTemp = y + dy[z];
                if (Position.testBounds((short)xTemp, (short)yTemp) &&
                    isTree(effects.getMapValue(xTemp, yTemp)))
                {
                    bitIndex++;
                }
            }

            int temp = treeTable[bitIndex & 15];

            if (temp != 0)
            {
                if (temp != (short)MapTileCharacters.WOODS)
                {
                    if (((x + y) & 1) != 0)
                    {
                        temp = temp - 8;
                    }
                }
                effects.setMapValue(x, y, (ushort)(temp | (ushort)MapTileBits.BLBNBIT));
            }
            else
            {
                if (!preserve)
                {
                    effects.setMapValue(x, y, (ushort)temp);
                }
            }
        }
        /// <summary>
        /// Smooth trees at a position.
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="preserve"></param>
        /// <param name="effects"></param>
        public void SmoothTreesAt(int x, int y, bool preserve, ToolEffects effects)
        {
            short[] dx        = { -1, 0, 1, 0 };
            short[] dy        = { 0, 1, 0, -1 };
            short[] treeTable =
            {
                0,   0,  0, 34,
                0,   0, 36, 35,
                0,  32,  0, 33,
                30, 31, 29, 37,
            };

            if (!IsTree(effects.GetMapValue(x, y)))
            {
                return;
            }

            int bitIndex = 0;
            int z;

            for (z = 0; z < 4; z++)
            {
                bitIndex = bitIndex << 1;
                int xTemp = x + dx[z];
                int yTemp = y + dy[z];
                if (Position.TestBounds(xTemp, yTemp) &&
                    IsTree(effects.GetMapValue(xTemp, yTemp)))
                {
                    bitIndex++;
                }
            }

            int temp = treeTable[bitIndex & 15];

            if (temp.IsTrue())
            {
                if (temp != (ushort)MapTileCharacters.WOODS)
                {
                    if (((x + y) & 1).IsTrue())
                    {
                        temp = temp - 8;
                    }
                }
                effects.SetMapValue(x, y, (ushort)(temp | (ushort)MapTileBits.Bulldozable));
            }
            else
            {
                if (!preserve)
                {
                    effects.SetMapValue(x, y, (ushort)temp);
                }
            }
        }
Esempio n. 5
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);
        }
Esempio n. 6
0
        /// <summary>
        /// Update connections (rails, and wire connections) to a zone.
        /// </summary>
        /// <param name="x">X -Where</param>
        /// <param name="y">Y - Where</param>
        /// <param name="effects">Modification Collecting Collection</param>
        public void FixZone(int x, int y, ToolEffects effects)
        {
            FixSingle(x, y, effects);

            if (y > 0)
            {
                FixSingle(x, y - 1, effects);
            }

            if (x < Constants.WorldWidth - 1)
            {
                FixSingle(x + 1, y, effects);
            }

            if (y < Constants.WorldHeight - 1)
            {
                FixSingle(x, y + 1, effects);
            }

            if (x > 0)
            {
                FixSingle(x - 1, y, effects);
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Modify road, rails, and wire connections at a given tile.
        ///
        /// 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>
        public void FixSingle(int x, int y, ToolEffects effects)
        {
            ushort adjTile = 0;

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

            tile = NeutralizeRoad(tile);

            if (tile >= (ushort)MapTileCharacters.ROADS && tile <= (ushort)MapTileCharacters.INTERSECTION)
            {           /* Cleanup Road */
                if (y > 0)
                {
                    tile = effects.GetMapTile(x, y - 1);
                    tile = NeutralizeRoad(tile);
                    if ((tile == (ushort)MapTileCharacters.HRAILROAD || (tile >= (ushort)MapTileCharacters.ROADBASE && tile <= (ushort)MapTileCharacters.VROADPOWER)) &&
                        tile != (ushort)MapTileCharacters.HROADPOWER && tile != (ushort)MapTileCharacters.VRAILROAD &&
                        tile != (ushort)MapTileCharacters.ROADBASE)
                    {
                        adjTile |= 0x0001;
                    }
                }

                if (x < Constants.WorldWidth - 1)
                {
                    tile = effects.GetMapTile(x + 1, y);
                    tile = NeutralizeRoad(tile);
                    if ((tile == (ushort)MapTileCharacters.VRAILROAD || (tile >= (ushort)MapTileCharacters.ROADBASE && tile <= (ushort)MapTileCharacters.VROADPOWER)) &&
                        tile != (ushort)MapTileCharacters.VROADPOWER && tile != (ushort)MapTileCharacters.HRAILROAD &&
                        tile != (ushort)MapTileCharacters.VBRIDGE)
                    {
                        adjTile |= 0x0002;
                    }
                }

                if (y < Constants.WorldWidth - 1)
                {
                    tile = effects.GetMapTile(x, y + 1);
                    tile = NeutralizeRoad(tile);
                    if ((tile == (ushort)MapTileCharacters.HRAILROAD || (tile >= (ushort)MapTileCharacters.ROADBASE && tile <= (ushort)MapTileCharacters.VROADPOWER)) &&
                        tile != (ushort)MapTileCharacters.HROADPOWER && tile != (ushort)MapTileCharacters.VRAILROAD &&
                        tile != (ushort)MapTileCharacters.ROADBASE)
                    {
                        adjTile |= 0x0004;
                    }
                }

                if (x > 0)
                {
                    tile = effects.GetMapTile(x - 1, y);
                    tile = NeutralizeRoad(tile);
                    if ((tile == (ushort)MapTileCharacters.VRAILROAD || (tile >= (ushort)MapTileCharacters.ROADBASE && tile <= (ushort)MapTileCharacters.VROADPOWER)) &&
                        tile != (ushort)MapTileCharacters.VROADPOWER && tile != (ushort)MapTileCharacters.HRAILROAD &&
                        tile != (ushort)MapTileCharacters.VBRIDGE)
                    {
                        adjTile |= 0x0008;
                    }
                }

                effects.SetMapValue(x, y, (ushort)(RoadTable[adjTile] | (ushort)MapTileBits.Bulldozable | (ushort)MapTileBits.Burnable));
                return;
            }

            if (tile >= (ushort)MapTileCharacters.LHRAIL && tile <= (ushort)MapTileCharacters.LVRAIL10)
            {         /* Cleanup Rail */
                if (y > 0)
                {
                    tile = effects.GetMapTile(x, y - 1);
                    tile = NeutralizeRoad(tile);
                    if (tile >= (ushort)MapTileCharacters.RAILHPOWERV && tile <= (ushort)MapTileCharacters.VRAILROAD &&
                        tile != (ushort)MapTileCharacters.RAILHPOWERV && tile != (ushort)MapTileCharacters.HRAILROAD &&
                        tile != (ushort)MapTileCharacters.HRAIL)
                    {
                        adjTile |= 0x0001;
                    }
                }

                if (x < Constants.WorldWidth - 1)
                {
                    tile = effects.GetMapTile(x + 1, y);
                    tile = NeutralizeRoad(tile);
                    if (tile >= (ushort)MapTileCharacters.RAILHPOWERV && tile <= (ushort)MapTileCharacters.VRAILROAD &&
                        tile != (ushort)MapTileCharacters.RAILVPOWERH && tile != (ushort)MapTileCharacters.VRAILROAD &&
                        tile != (ushort)MapTileCharacters.VRAIL)
                    {
                        adjTile |= 0x0002;
                    }
                }

                if (y < Constants.WorldWidth - 1)
                {
                    tile = effects.GetMapTile(x, y + 1);
                    tile = NeutralizeRoad(tile);
                    if (tile >= (ushort)MapTileCharacters.RAILHPOWERV && tile <= (ushort)MapTileCharacters.VRAILROAD &&
                        tile != (ushort)MapTileCharacters.RAILHPOWERV && tile != (ushort)MapTileCharacters.HRAILROAD &&
                        tile != (ushort)MapTileCharacters.HRAIL)
                    {
                        adjTile |= 0x0004;
                    }
                }

                if (x > 0)
                {
                    tile = effects.GetMapTile(x - 1, y);
                    tile = NeutralizeRoad(tile);
                    if (tile >= (ushort)MapTileCharacters.RAILHPOWERV && tile <= (ushort)MapTileCharacters.VRAILROAD &&
                        tile != (ushort)MapTileCharacters.RAILVPOWERH && tile != (ushort)MapTileCharacters.VRAILROAD &&
                        tile != (ushort)MapTileCharacters.VRAIL)
                    {
                        adjTile |= 0x0008;
                    }
                }

                effects.SetMapValue(x, y, (ushort)(RailTable[adjTile] | (ushort)MapTileBits.Bulldozable | (ushort)MapTileBits.Burnable));
                return;
            }

            if (tile >= (ushort)MapTileCharacters.LHPOWER && tile <= (ushort)MapTileCharacters.LVPOWER10)
            {         /* Cleanup Wire */
                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.VPOWER && tile != (ushort)MapTileCharacters.VROADPOWER && tile != (ushort)MapTileCharacters.RAILVPOWERH)
                        {
                            adjTile |= 0x0001;
                        }
                    }
                }

                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.HPOWER && tile != (ushort)MapTileCharacters.HROADPOWER && tile != (ushort)MapTileCharacters.RAILHPOWERV)
                        {
                            adjTile |= 0x0002;
                        }
                    }
                }

                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.VPOWER && tile != (ushort)MapTileCharacters.VROADPOWER && tile != (ushort)MapTileCharacters.RAILVPOWERH)
                        {
                            adjTile |= 0x0004;
                        }
                    }
                }

                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.HPOWER && tile != (ushort)MapTileCharacters.HROADPOWER && tile != (ushort)MapTileCharacters.RAILHPOWERV)
                        {
                            adjTile |= 0x0008;
                        }
                    }
                }

                effects.SetMapValue(x, y, (ushort)(WireTable[adjTile] | (ushort)MapTileBits.BurnableOrBulldozableOrConductive));
                return;
            }
        }
Esempio n. 8
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);
        }
Esempio n. 9
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);
        }
Esempio n. 10
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);
        }
Esempio n. 11
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);
        }