Exemple #1
0
        public void ManualPrintMapArea()
        {
            var area = new MapArea();

            area.Add(1, 2);
            area.Add(1, 2);
            area.Add(2, 3);
            area.Add(2, 4);

            Console.WriteLine(area);
        }
Exemple #2
0
        public void TestMapArea()
        {
            var map = new MapArea();

            Assert.AreEqual(0, map.Count);

            map.Add(1, 1);
            Assert.AreEqual(1, map.Count);

            map.Add(1, 1);
            Assert.AreEqual(1, map.Count);

            map.Add(2, 1);
            Assert.AreEqual(2, map.Count);
        }
Exemple #3
0
        private MapArea GenerateArea(MapInfo mapInfo, RoomConnection connectAt, IGenerator rng)
        {
            MapArea area     = new MapArea();
            int     numRects = rng.Next(MinRects, MaxRects + 1);

            List <Rectangle> rects = new List <Rectangle>();

            Rectangle firstRect = new Rectangle(0, 0, rng.Next(MinBounds.Width, MaxBounds.Width), rng.Next(MinBounds.Height, MaxBounds.Height));

            Coord offset = connectAt.Direction.Type switch
            {
                Direction.Types.LEFT => new Coord(-firstRect.Width + 1, -firstRect.Height / 2),
                Direction.Types.RIGHT => new Coord(0, -firstRect.Height / 2),
                Direction.Types.UP => new Coord(-firstRect.Width / 2, -firstRect.Height + 1),
                Direction.Types.DOWN => new Coord(-firstRect.Width / 2, 0),
                Direction.Types.NONE => new Coord(-firstRect.Height / 2, -firstRect.Width / 2),
                _ => throw new ArgumentOutOfRangeException()
            };

            firstRect = firstRect.WithPosition(offset + connectAt.Position);

            rects.Add(firstRect);
            area.Add(firstRect);

            int fails = 0;

            while (rects.Count < numRects && fails < 200)
            {
                Rectangle previousRectangle = rects[^ 1];
Exemple #4
0
        public void Decorate(Floor floor, MapArea area, IGenerator rng)
        {
            MapArea restrictedArea = new MapArea();

            restrictedArea.Add(area.Positions);
            restrictedArea.Remove(area.Bounds.PerimeterPositions());

            Placeable.Place(floor, restrictedArea.RandomPosition(rng), rng);
        }
Exemple #5
0
        public IRoom Generate(Floor floor, Coord connectFrom, Coord connectTo, IGenerator rng)
        {
            _floor.Place(floor, connectFrom, rng);
            _floor.Place(floor, connectTo, rng);

            List <Coord> path = HorizontalVerticalPath(connectFrom, connectTo).ToList();

            MapArea area = new MapArea();

            for (int i = 1; i < path.Count - 1; i++)
            {
                Coord current = path[i];
                Coord next    = path[i + 1];
                Coord prev    = path[i - 1];

                area.Add(current);

                if (floor.MapInfo.Map.Terrain[current] != null && floor.MapInfo.Map.Terrain[current].IsWalkable)
                {
                    continue;
                }

                _floor.Place(floor, current, rng);


                HashSet <Coord> wallOptions = new HashSet <Coord> {
                    current + Direction.UP, current + Direction.RIGHT, current + Direction.DOWN, current + Direction.LEFT
                };
                wallOptions.Remove(prev);
                wallOptions.Remove(next);

                foreach (Coord pos in wallOptions)
                {
                    if (floor.MapInfo.Map.Terrain[pos] == null)
                    {
                        _wall.Place(floor, pos, rng);
                    }
                }
            }

            Direction      finalDirection  = Direction.GetCardinalDirection(path[path.Count - 2], path[path.Count - 1]);
            RoomConnection finalConnection = new RoomConnection(connectTo, finalDirection, _endPossibilities, false);


            return(new BasicRoom(area, new List <RoomConnection> {
                finalConnection
            }, null));
        }
Exemple #6
0
        public void Decorate(Floor floor, MapArea area, IGenerator rng)
        {
            MapArea restrictedArea = new MapArea();

            restrictedArea.Add(area.Positions);
            restrictedArea.Remove(area.Bounds.PerimeterPositions());

            int amount       = Math.Min(rng.Next(MinAmount, MaxAmount + 1), restrictedArea.Count);
            int amountPlaced = 0;

            while (amountPlaced < amount)
            {
                if (Placeable.Place(floor, restrictedArea.RandomPosition(rng), rng))
                {
                    amountPlaced += 1;
                }
            }
        }
Exemple #7
0
        public void TestMapAreaRemove()
        {
            var mapArea = new MapArea();

            mapArea.Add(GoRogue.Utility.Yield(Coord.Get(1, 1), Coord.Get(2, 2), Coord.Get(3, 2)));

            Assert.AreEqual(3, mapArea.Count);
            Assert.AreEqual(1, mapArea.Bounds.X);
            Assert.AreEqual(1, mapArea.Bounds.Y);
            Assert.AreEqual(3, mapArea.Bounds.MaxExtentX);
            Assert.AreEqual(2, mapArea.Bounds.MaxExtentY);

            mapArea.Remove(Coord.Get(3, 2));

            Assert.AreEqual(2, mapArea.Count);
            Assert.AreEqual(1, mapArea.Bounds.X);
            Assert.AreEqual(1, mapArea.Bounds.Y);
            Assert.AreEqual(2, mapArea.Bounds.MaxExtentX);
            Assert.AreEqual(2, mapArea.Bounds.MaxExtentY);
        }
        public IRoom Generate(Floor floor, RoomConnection connectAt, IGenerator rng)
        {
            Rectangle roomBounds = new Rectangle(0, 0, rng.Next(_minBounds.Width, _maxBounds.Width), rng.Next(_minBounds.Height, _maxBounds.Height));

            Coord offset = connectAt.Direction.Type switch
            {
                Direction.Types.LEFT => new Coord(-roomBounds.Width + 1, -roomBounds.Height / 2),
                Direction.Types.RIGHT => new Coord(0, -roomBounds.Height / 2),
                Direction.Types.UP => new Coord(-roomBounds.Width / 2, -roomBounds.Height + 1),
                Direction.Types.DOWN => new Coord(-roomBounds.Width / 2, 0),
                Direction.Types.NONE => new Coord(-roomBounds.Height / 2, -roomBounds.Width / 2),
                _ => throw new ArgumentOutOfRangeException()
            };

            roomBounds = roomBounds.WithPosition(offset + connectAt.Position);


            foreach (Coord pos in roomBounds.PerimeterPositions())
            {
                _wall.Place(floor, pos, rng);
            }

            foreach (Coord pos in roomBounds.ChangeSize(-2, -2).WithCenter(roomBounds.Center).Positions())
            {
                _floor.Place(floor, pos, rng);
            }

            MapArea area = new MapArea();

            area.Add(roomBounds);

            List <RoomConnection> connections = new List <RoomConnection>();

            foreach (Direction dir in AdjacencyRule.CARDINALS.DirectionsOfNeighbors())
            {
                if (dir.DeltaX == -connectAt.Direction.DeltaX && dir.DeltaY == -connectAt.Direction.DeltaY)
                {
                    continue;
                }

                int xOffset = dir.DeltaX * (roomBounds.Width - 1) / 2;
                int yOffset = dir.DeltaY * (roomBounds.Height - 1) / 2;

                if (dir.DeltaX == 0)
                {
                    xOffset += rng.Next(-roomBounds.Width / 2 + 1, roomBounds.Width / 2 - 1);
                }

                if (dir.DeltaY == 0)
                {
                    yOffset += rng.Next(-roomBounds.Height / 2 + 1, roomBounds.Height / 2 - 1);
                }

                Coord door = roomBounds.Center + new Coord(xOffset, yOffset);
                connections.Add(new RoomConnection(door, dir, NeighborPossibilities, true));
                //_floor.Place(mapInfo, door, rng);
            }

            if (connectAt.Position != Coord.NONE)
            {
                _floor.Place(floor, connectAt.Position, rng);
            }

            return(new BasicRoom(area, connections, this));
        }
Exemple #9
0
        public void InitializeApiStart2(dynamic data)
        {
            string APIName = "api_start2";

            if (data.api_data != null && data.api_result == 1)
            {
                data = data.api_data;
            }

            //特別置換処理
            data.api_mst_stype[7].api_name = "巡洋戦艦";

            ClearUpdated();

            //api_mst_ship
            foreach (var elem in data.api_mst_ship)
            {
                int id = (int)elem.api_id;
                if (MasterShips[id] == null)
                {
                    var ship = new ShipDataMaster();
                    ship.LoadFromResponse(APIName, elem);
                    MasterShips.Add(ship);
                }
                else
                {
                    MasterShips[id].LoadFromResponse(APIName, elem);
                }
            }

            //改装関連のデータ設定
            foreach (var ship in MasterShips)
            {
                var remodelID = ship.Value.RemodelAfterShipID;
                if (remodelID != 0)
                {
                    MasterShips[remodelID].RemodelBeforeShipID = ship.Key;
                }
            }

            //api_mst_shipgraph
            foreach (var elem in data.api_mst_shipgraph)
            {
                int            id   = (int)elem.api_id;
                ShipDataMaster ship = MasterShips[id];
                if (ship != null)
                {
                    ship.ResourceName = elem.api_filename;
                    dynamic versions = elem.api_version;
                    ship.ResourceGraphicVersion   = versions[0];
                    ship.ResourceVoiceVersion     = versions[1];
                    ship.ResourcePortVoiceVersion = versions[2];
                }
            }

            //api_mst_slotitem_equiptype
            foreach (var elem in data.api_mst_slotitem_equiptype)
            {
                int id = (int)elem.api_id;
                if (EquipmentTypes[id] == null)
                {
                    var eqt = new EquipmentType();
                    eqt.LoadFromResponse(APIName, elem);
                    EquipmentTypes.Add(eqt);
                }
                else
                {
                    EquipmentTypes[id].LoadFromResponse(APIName, elem);
                }
            }


            //api_mst_stype
            foreach (var elem in data.api_mst_stype)
            {
                int id = (int)elem.api_id;
                if (ShipTypes[id] == null)
                {
                    var spt = new ShipType();
                    spt.LoadFromResponse(APIName, elem);
                    ShipTypes.Add(spt);
                }
                else
                {
                    ShipTypes[id].LoadFromResponse(APIName, elem);
                }
            }


            //api_mst_slotitem
            foreach (var elem in data.api_mst_slotitem)
            {
                int id = (int)elem.api_id;
                if (MasterEquipments[id] == null)
                {
                    var eq = new EquipmentDataMaster();
                    eq.LoadFromResponse(APIName, elem);
                    MasterEquipments.Add(eq);
                }
                else
                {
                    MasterEquipments[id].LoadFromResponse(APIName, elem);
                }
            }

            //api_mst_slotitemgraph

            /*
             *          foreach ( var elem in data.api_mst_slotitemgraph ) {
             *
             *                  int id = (int)elem.api_id;
             *                  EquipmentDataMaster eq = db.MasterEquipments[id];
             *                  if ( eq != null ) {
             *                          eq.ResourceVersion = elem.api_version;
             *                  }
             *          }
             */

            //api_mst_useitem
            foreach (var elem in data.api_mst_useitem)
            {
                int id = (int)elem.api_id;
                if (MasterUseItems[id] == null)
                {
                    var item = new UseItemMaster();
                    item.LoadFromResponse(APIName, elem);
                    MasterUseItems.Add(item);
                }
                else
                {
                    MasterUseItems[id].LoadFromResponse(APIName, elem);
                }
            }

            //api_mst_maparea
            foreach (var elem in data.api_mst_maparea)
            {
                int id = (int)elem.api_id;
                if (MapArea[id] == null)
                {
                    var item = new MapAreaData();
                    item.LoadFromResponse(APIName, elem);
                    MapArea.Add(item);
                }
                else
                {
                    MapArea[id].LoadFromResponse(APIName, elem);
                }
            }

            //api_mst_mapinfo
            foreach (var elem in data.api_mst_mapinfo)
            {
                int id = (int)elem.api_id;
                if (MapInfo[id] == null)
                {
                    var item = new MapInfoData();
                    item.LoadFromResponse(APIName, elem);
                    MapInfo.Add(item);
                }
                else
                {
                    MapInfo[id].LoadFromResponse(APIName, elem);
                }
            }

            //api_mst_mission
            foreach (var elem in data.api_mst_mission)
            {
                int id = (int)elem.api_id;
                if (Mission[id] == null)
                {
                    var item = new MissionData();
                    item.LoadFromResponse(APIName, elem);
                    Mission.Add(item);
                }
                else
                {
                    Mission[id].LoadFromResponse(APIName, elem);
                }
            }

            //api_mst_shipupgrade
            Dictionary <int, int> upgradeLevels = new Dictionary <int, int>();

            foreach (var elem in data.api_mst_shipupgrade)
            {
                int idbefore   = (int)elem.api_current_ship_id;
                int idafter    = (int)elem.api_id;
                var shipbefore = MasterShips[idbefore];
                var shipafter  = MasterShips[idafter];
                int level      = (int)elem.api_upgrade_level;

                if (upgradeLevels.ContainsKey(idafter))
                {
                    if (level < upgradeLevels[idafter])
                    {
                        shipafter.RemodelBeforeShipID = idbefore;
                        upgradeLevels[idafter]        = level;
                    }
                }
                else
                {
                    shipafter.RemodelBeforeShipID = idbefore;
                    upgradeLevels.Add(idafter, level);
                }

                if (shipbefore != null)
                {
                    shipbefore.NeedBlueprint = (int)elem.api_drawing_count;
                    shipbefore.NeedCatapult  = (int)elem.api_catapult_count;
                }
            }
        }
Exemple #10
0
 public void MoveTo(Coord position)
 {
     Path.Push(position);
     AllPositions.Add(position);
     CurrentPosition = position;
 }