示例#1
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;
            }
        }
示例#2
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);
        }
示例#3
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);
        }
示例#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);
        }