/// <summary>
 ///
 /// </summary>
 /// <param name="view"></param>
 /// <param name="loc"></param>
 /// <param name="ab"></param>
 public override void OnClick(MapViewWindow view, Location loc, Point ab)
 {
     if (IsPlacing)
     {
         if (!selectedType.CanBeBuilt(loc, height))
         {
             MessageBox.Show("Can not build");
             //! MessageBox.Show("設置できません");
         }
         else
         {
             CompletionHandler handler = new CompletionHandler(selectedType, loc, height, true);
             new ConstructionSite(loc, new EventHandler(handler.handle),
                                  new Distance(selectedType.Size, height));
         }
     }
     else
     {
         VarHeightBuilding building = VarHeightBuilding.get(loc);
         if (building != null)
         {
             building.remove();
         }
     }
 }
예제 #2
0
        public static int RunMapViewer(MapViewerOption option)
        {
            if (!File.Exists(option.Filename))
            {
                Console.WriteLine("file not found!");
                return(1);
            }

            var textMap = File.ReadAllText(option.Filename);

            if (!option.Window)
            {
                try
                {
                    Console.WriteLine(textMap);
                    return(0);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    return(1);
                }
            }

            MapViewWindow.OpenGlWindow(textMap, option.BlockSize);
            return(0);
        }
예제 #3
0
        public override void onClick(MapViewWindow view, Location loc, Point ab)
        {
            JunctionRailRoad jrr = JunctionRailRoad.get(loc);

            if (jrr != null)
            {
                Form dialog = new JunctionConfigDialog(controller.getOrCreateJunction(loc));
                dialog.ShowDialog(MainWindow.mainWindow);
                return;
            }

            Voxel v = World.world[loc];

            if (v == null)
            {
                return;
            }

            TrainHarbor harbor = (TrainHarbor)v.queryInterface(typeof(TrainHarbor));

            if (harbor != null)
            {
                StationHandler      handler = controller.getStationHandler(harbor);
                StationConfigDialog dialog  = new StationConfigDialog(handler);
                dialog.ShowDialog(MainWindow.mainWindow);
                controller.setStationHandler(harbor, dialog.currentHandler);
                return;
            }
        }
예제 #4
0
 public override void onClick(MapViewWindow source, Location loc, Point ab)
 {
     if (anchor == UNPLACED)
     {
         anchor = loc;
         sameLevelDisambiguator = new SameLevelDisambiguator(anchor.z);
     }
     else
     {
         loc = align(loc);
         if (anchor != loc)
         {
             if (isPlacing)
             {
                 if (type.canBeBuilt(anchor, loc))
                 {
                     // build new railroads.
                     type.build(anchor, loc);
                 }
             }
             else
             {
                 // remove existing ones
                 type.remove(anchor, loc);
             }
             World.world.onVoxelUpdated(Cube.createInclusive(anchor, loc));
         }
         anchor = UNPLACED;
     }
 }
예제 #5
0
        public override void onClick(MapViewWindow view, Location loc, Point ab)
        {
            if (isPlacing)
            {
                TrafficVoxel tv = TrafficVoxel.getOrCreate(loc);
                if (tv == null)
                {
                    MainWindow.showError("There are obstacles");
                    //! MainWindow.showError("障害物があります");
                    return;
                }

                if (tv.railRoad == null || tv.railRoad is SingleRailRoad)
                {
                    new SignalRailRoad(tv, currentType, currentDirection);
                }
                else
                {
                    MainWindow.showError("Can not place on this rail");
                }
                //! MainWindow.showError("設置できない線路です");
            }
            else
            {
                SignalRailRoad srr = RailRoad.get(loc) as SignalRailRoad;
                if (srr != null)
                {
                    srr.remove();
                }
            }
        }
예제 #6
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="source"></param>
 /// <param name="location"></param>
 /// <param name="ab"></param>
 public override void OnClick(MapViewWindow source, Location location, Point ab)
 {
     if (anchor == unplaced)
     {
         anchor = location;
         sameLevelDisambiguator = new SameLevelDisambiguator(anchor.z);
     }
     else
     {
         if (anchor != location)
         {
             if (IsPlacing)
             {
                 // build new railroads.
                 if (!SingleRailRoad.Build(anchor, location))
                 {
                     MessageBox.Show(Translation.GetString("CONTROLLER_RAIL_OBSTACLES"), "Error");
                 }
             }
             else
             {
                 // remove existing ones
                 SingleRailRoad.Remove(anchor, location);
             }
         }
         anchor = unplaced;
     }
     UpdateDialog();
 }
예제 #7
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="source"></param>
 /// <param name="loc"></param>
 /// <param name="ab"></param>
 public void OnClick(MapViewWindow source, Location loc, Point ab)
 {
     if (anchor == Unplaced)
     {
         if (remover)
         {
             if (null == WorldDefinition.World[loc] as HalfDividedVoxel)
             {
                 return;
             }
         }
         else
         {
             if (!HalfVoxelContribution.CanBeBuilt(loc))
             {
                 return;
             }
         }
         anchor                 = loc;
         currentPos             = loc;
         curSide                = getSide(ab);
         sameLevelDisambiguator = new SameLevelDisambiguator(anchor.z);
     }
     else
     {
         if (!currentPos.Equals(anchor))
         {
             OnVoxelSelected(anchor, front, currentSide);
         }
         WorldDefinition.World.OnVoxelUpdated(anchor);
         anchor = Unplaced;
     }
 }
        public void onClick(MapViewWindow source, Location loc, Point ab)
        {
            Point p = World.world.fromXYZToAB(loc);
            int   x = ab.X - p.X;
            int   y = ab.Y - p.Y;

            Debug.WriteLine("diff=(" + x + "," + y + ")");
            Direction d;

            if (x < 15)
            {
                if (y < 15)
                {
                    d = Direction.NORTH;
                }
                else
                {
                    d = Direction.WEST;
                }
            }
            else
            if (y < 15)
            {
                d = Direction.EAST;
            }
            else
            {
                d = Direction.SOUTH;
            }
            onBorderSelected(loc, d);
        }
예제 #9
0
        public override void onClick(MapViewWindow source, Location loc, Point ab)
        {
            if (anchor == UNPLACED)
            {
                anchor = loc;
                sameLevelDisambiguator = new SameLevelDisambiguator(anchor.z);
            }
            else
            {
                if (anchor != loc)
                {
                    if (isPlacing)
                    {
                        // build new railroads.
                        if (!SingleRailRoad.build(anchor, loc))
                        {
                            MainWindow.showError("There are obstacles");
                        }
                        //! MainWindow.showError("障害物があります");
                    }
                    else
                    {
                        // remove existing ones
                        SingleRailRoad.remove(anchor, loc);
                    }
                }
                anchor = UNPLACED;
            }

            updateDialog();
        }
예제 #10
0
        public void onClick(MapViewWindow view, Location loc, Point ab)
        {
            if (World.world[loc] != null)
            {
                MainWindow.showError("There are obstacles");
                //! MainWindow.showError("障害物があります");
                return;
            }
            // TODO: remove reclaimable voxels automatically

            int height = World.world.getGroundLevel(loc);

            byte[] h  = new byte[4];
            int[]  dx = new int[] { 1, 1, 0, 0 };
            int[]  dy = new int[] { -1, 0, 0, -1 };
            for (int i = 0; i < 4; i++)
            {
                h[i] = (byte)(getHeight(new Location(loc.x + dx[i], loc.y + dy[i], loc.z)) - height * 4);
            }

            if (h[0] == 0 && h[1] == 0 && h[2] == 0 && h[3] == 0)
            {
                return;
            }

            new MountainVoxel(loc,
                              h[0], h[1], h[2], h[3]);
        }
예제 #11
0
        /// <summary>
        /// Selects the south-western voxel of the point selected by the mouse.
        /// The loc parameter and the ab parameter should point to the same location.
        /// </summary>
        private Location selectVoxel(MapViewWindow view, Location loc, Point ab)
        {
            // top-left corner of the selected location
            Point vxl = World.world.fromXYZToAB(loc);

            Point offset = new Point(ab.X - vxl.X, ab.Y - vxl.Y);

            if (offset.X < 8)
            {
                loc.x--;
            }
            else
            if (offset.X >= 24)
            {
                loc.y++;
            }
            else
            {
                MountainVoxel mv = MountainVoxel.get(loc);
                int           h0 = (mv != null)?(int)mv.getHeight(Direction.NORTHEAST):0;
                int           h2 = (mv != null)?(int)mv.getHeight(Direction.SOUTHWEST):0;

                if (offset.Y >= (16 - (h0 + h2) * 4) / 2)
                {
                    loc.x--; loc.y++;
                }
            }

            return(loc);
        }
예제 #12
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="source"></param>
 /// <param name="loc"></param>
 /// <param name="ab"></param>
 public override void OnClick(MapViewWindow source, Location loc, Point ab)
 {
     if (anchor == Unplaced)
     {
         anchor = loc;
         sameLevelDisambiguator = new SameLevelDisambiguator(anchor.z);
     }
     else
     {
         loc = align(loc);
         if (anchor != loc)
         {
             if (isPlacing)
             {
                 if (Type.CanBeBuilt(anchor, loc))
                 {
                     // build new railroads.
                     Type.Build(anchor, loc);
                 }
             }
             else
             {
                 // remove existing ones
                 Type.Remove(anchor, loc);
             }
             WorldDefinition.World.OnVoxelUpdated(Cube.CreateInclusive(anchor, loc));
         }
         anchor = Unplaced;
     }
 }
예제 #13
0
        public void onClick(MapViewWindow view, Location loc, Point ab)
        {
            MountainVoxel mv = World.world[loc] as MountainVoxel;

            if (mv == null)
            {
                MainWindow.showError("Can only be placed on mountainsides");
                //! MainWindow.showError("山肌しか工事できません");
                return;
            }

            int h = World.world.getGroundLevel(loc);

            for (int i = 0; i < 4; i++)
            {
                if (World.world.getGroundLevel(loc + Direction.get(i * 2)) > h)
                {
                    MainWindow.showError("This location is inappropriate");
                    //! MainWindow.showError("設置位置が不適切です");
                    return;
                }
            }

            World.world.remove(mv);
        }
예제 #14
0
 public override void onClick(MapViewWindow view, Location loc, Point ab)
 {
     if (!canBeBuilt(loc))
     {
         MainWindow.showError("Can not build");
     }
     //! MainWindow.showError("設置できません");
     else
     {
         if (current.current is VarHeightBuildingContribution)
         {
             VarHeightBuildingContribution vhContrib = (VarHeightBuildingContribution)current.current;
             CompletionHandler             handler   = new CompletionHandler(vhContrib, loc, (int)numHeight.Value, true);
             new ConstructionSite(loc, new EventHandler(handler.handle),
                                  new Distance(vhContrib.size, (int)numHeight.Value));
         }
         else
         {
             CommercialStructureContribution csContrib = (CommercialStructureContribution)current.current;
             if (csContrib.size.volume > 0)                    // eliminate dummy contribution
             {
                 CompletionHandler handler = new CompletionHandler(csContrib, loc, current.maxHeight, true);
                 new ConstructionSite(loc, new EventHandler(handler.handle), csContrib.size);
             }
         }
     }
     randomize();
 }
예제 #15
0
 public override void onMouseMove(MapViewWindow view, Location loc, Point ab)
 {
     if (Keyboard.isShiftKeyPressed)
     {
         loc = selectVoxel(view, loc, ab);
         raiseLowerLand(loc);
     }
 }
예제 #16
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="view"></param>
 /// <param name="loc"></param>
 /// <param name="ab"></param>
 public override void OnMouseMove(MapViewWindow view, Location loc, Point ab)
 {
     if (SdlDotNet.Input.Keyboard.IsKeyPressed(SdlDotNet.Input.Key.LeftShift) || SdlDotNet.Input.Keyboard.IsKeyPressed(SdlDotNet.Input.Key.RightShift))
     {
         loc = selectVoxel(view, loc, ab);
         raiseLowerLand(loc);
     }
 }
예제 #17
0
        /// <summary>
        /// Removes the structure from given location, if any.
        /// </summary>
        public override void remove(MapViewWindow view, Location loc)
        {
            StadiumStructure c = World.world.getEntityAt(loc) as StadiumStructure;

            if (c != null)
            {
                c.remove();
            }
        }
예제 #18
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="view"></param>
        /// <param name="loc"></param>
        public override void Remove(MapViewWindow view, Location loc)
        {
            RailStationaryStructure s = RailStationaryStructure.get(loc);

            if (s != null)
            {
                s.remove();
            }
        }
        static int _runFinder(IFinder finder, IHeuristic h, IMap map, bool window, bool noshow, int blocksize, int sleep)
        {
            if (!noshow)
            {
                if (sleep > 0)
                {
                    finder.SleepUITimeInMs = sleep;
                }

                var viewer =
                    window ?
                    ViewerFactory.GetOpenGlViewerImplementation(blocksize)
                    : ViewerFactory.GetConsoleViewerImplementation();


                viewer.SetFinder(finder);
                viewer.Run(map, h);
            }
            else
            {
                if (finder.Find(map, h))
                {
                    var path = map.GetPath();

                    AbstractViewer.ShowEndLog(finder, path, new Pathfinder.Abstraction.FinderEventArgs
                    {
                        Finded             = true,
                        GridMap            = map,
                        ExpandedNodesCount = map.GetMaxExpandedNodes(),
                        PassedTimeInMs     = finder.GetProcessedTime(),
                        Step = 0
                    });

                    var result = FileTool.GetTextRepresentation(map, false, path);

                    if (!window)
                    {
                        Console.WriteLine(result);
                    }
                    else
                    {
                        MapViewWindow.OpenGlWindow(result, blocksize);
                    }
                }
                else
                {
                    Console.WriteLine("Cant find a path");
                }
            }



            return(0);
        }
예제 #20
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="source"></param>
        /// <param name="loc"></param>
        /// <param name="ab"></param>
        public virtual void OnMouseMove(MapViewWindow source, Location loc, Point ab)
        {
            if (currentPos != Location.Unplaced)
            {
                WorldDefinition.World.OnVoxelUpdated(currentPos);
            }
            currentPos = loc;
            WorldDefinition.World.OnVoxelUpdated(currentPos);

            onSelectionChanged(currentPos);
        }
예제 #21
0
        public virtual void onMouseMove(MapViewWindow source, Location loc, Point ab)
        {
            if (currentPos != Location.UNPLACED)
            {
                World.world.onVoxelUpdated(currentPos);
            }
            currentPos = loc;
            World.world.onVoxelUpdated(currentPos);

            onSelectionChanged(currentPos);
        }
예제 #22
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="view"></param>
        /// <param name="loc"></param>
        /// <param name="ab"></param>
        public void OnMouseMove(MapViewWindow view, Location loc, Point ab)
        {
            if (anchor != Unplaced)
            {
                currentPos = align(loc);
                curSide    = getSide(ab);
                //if( !currentPos.Equals(anchor) )
                //onVoxelUpdated(anchor,front,currentSide);

                WorldDefinition.World.OnVoxelUpdated(anchor);
            }
        }
예제 #23
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="view"></param>
        /// <param name="loc"></param>
        /// <param name="ab"></param>
        public override void OnMouseMove(MapViewWindow view, Location loc, Point ab)
        {
            WorldDefinition w = WorldDefinition.World;

            if (baseLoc != loc)
            {
                // update the screen
                updateVoxels();
                baseLoc = loc;
                updateVoxels();
            }
        }
예제 #24
0
        public override void onMouseMove(MapViewWindow view, Location loc, Point ab)
        {
            World w = World.world;

            if (baseLoc != loc)
            {
                // update the screen
                w.onVoxelUpdated(baseLoc);
                baseLoc = loc;
                w.onVoxelUpdated(baseLoc);
            }
        }
예제 #25
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="source"></param>
 /// <param name="loc"></param>
 /// <param name="ab"></param>
 public void OnRightClick(MapViewWindow source, Location loc, Point ab)
 {
     if (anchor == Unplaced)
     {
         close();        // cancel
     }
     else
     {
         WorldDefinition.World.OnVoxelUpdated(anchor);
         anchor = Unplaced;
     }
 }
예제 #26
0
 public override void onMouseMove(MapViewWindow view, Location loc, Point ab)
 {
     if (anchor != UNPLACED && isPlacing && currentPos != loc)
     {
         if (currentPos != UNPLACED)
         {
             World.world.onVoxelUpdated(Cube.createInclusive(anchor, currentPos));
         }
         currentPos = align(loc);
         World.world.onVoxelUpdated(Cube.createInclusive(anchor, currentPos));
     }
 }
예제 #27
0
        public override void onMouseMove(MapViewWindow view, Location loc, Point ab)
        {
            World w = World.world;

            if (baseLoc != loc)
            {
                // update the screen
                baseLoc = loc;
                // TODO: we need to correctly update the screen
                w.onAllVoxelUpdated();
            }
        }
예제 #28
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="view"></param>
 /// <param name="loc"></param>
 /// <param name="ab"></param>
 public virtual void OnClick(MapViewWindow view, Location loc, Point ab)
 {
     if (anchor == unplaced)
     {
         anchor = loc;
     }
     else
     {
         OnRectSelected(this.LocationNW, this.LocationSE);
         anchor = unplaced;
     }
 }
예제 #29
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="view"></param>
 /// <param name="loc"></param>
 /// <param name="ab"></param>
 public override void OnMouseMove(MapViewWindow view, Location loc, Point ab)
 {
     if (anchor != Unplaced && isPlacing && currentPos != loc)
     {
         if (currentPos != Unplaced)
         {
             WorldDefinition.World.OnVoxelUpdated(Cube.CreateInclusive(anchor, currentPos));
         }
         currentPos = align(loc);
         WorldDefinition.World.OnVoxelUpdated(Cube.CreateInclusive(anchor, currentPos));
     }
 }
예제 #30
0
 public virtual void onClick(MapViewWindow view, Location loc, Point ab)
 {
     if (anchor == UNPLACED)
     {
         anchor = loc;
     }
     else
     {
         onRectSelected(this.location1, this.location2);
         anchor = UNPLACED;
     }
 }