private static Room MakeRoom(Rct _rct, Random _random, ICollection<Point> _objects, Point _blockId) { var contains = new List<Point>(); foreach (var point in _objects) { if (_rct.Contains(point)) { contains.Add(point); } } var size = new Point(MIN_ROOM_SIZE + _random.Next(_rct.Width - MIN_ROOM_SIZE), MIN_ROOM_SIZE + _random.Next(_rct.Height - MIN_ROOM_SIZE)); for (;;) { var xy = new Point(_random.Next(_rct.Width - size.X + 1), _random.Next(_rct.Height - size.Y + 1)); var rect = new Rct(_rct.LeftTop + xy, size.X, size.Y); if (contains.Count == 0 || contains.All(rect.Contains)) { foreach (var contain in contains) { _objects.Remove(contain); } return new Room(rect, _rct, _blockId); } } }
public override void Resize(Rct _newRct) { base.Resize(_newRct); World.TheWorld.LiveMap.SetViewPortSize(new Point(ContentRct.Width, ContentRct.Height)); World.TheWorld.LiveMap.Reset(); World.TheWorld.UpdateDPoint(); }
public WorldMapGenerator(int _size, Random _rnd) { m_rnd = _rnd; m_size = _size; m_sqr = m_size * m_size; m_map = new ushort[m_size, m_size]; m_rct = new Rct(0, 0, m_size, m_size); m_zones = m_imax = m_size * m_size / 2; m_forbidToUnite = new bool[m_imax + 1]; m_sizes = new int[m_imax + 1]; m_neighbours = new bool[m_imax + 1, m_imax + 1]; m_united = new ushort[m_imax + 1]; m_infos.Add(EMapBlockTypes.SEA, new MapTypeInfo(BORDER_WATER_PART)); m_infos.Add(EMapBlockTypes.DEEP_SEA, new MapTypeInfo(0)); m_infos.Add(EMapBlockTypes.COAST, new MapTypeInfo(0)); m_infos.Add(EMapBlockTypes.LAKE_COAST, new MapTypeInfo(LAKE_COAST_PART)); m_infos.Add(EMapBlockTypes.FRESH_WATER, new MapTypeInfo(LAKE_PART)); m_infos.Add(EMapBlockTypes.DEEP_FRESH_WATER, new MapTypeInfo(0)); m_infos.Add(EMapBlockTypes.ETERNAL_SNOW, new MapTypeInfo(MOUNT_PART)); m_infos.Add(EMapBlockTypes.MOUNT, new MapTypeInfo(0)); m_infos.Add(EMapBlockTypes.GROUND, new MapTypeInfo(0)); m_infos.Add(EMapBlockTypes.FOREST, new MapTypeInfo(FOREST_PART)); m_infos.Add(EMapBlockTypes.SWAMP, new MapTypeInfo(SWAMP_PART)); m_infos.Add(EMapBlockTypes.SHRUBS, new MapTypeInfo(0)); }
public BackpackUiBlock(Rct _rct, AskMessage _message) : base(_rct, _message.GetFirstParameter<ESelectItemDialogBehavior>(), _message.Act, World.TheWorld.Avatar.GetBackPackItems().OrderBy(_thingDescriptor => _thingDescriptor.UiOrderIndex)) { var category = _message.GetParameters<EItemCategory>(); m_allowedCategories = category ?? new EItemCategory[0]; }
public SelectTargetUiBlock(TurnMessageUiBlock _messages, Rct _mapRct, AskMessage _message) : base(_mapRct, null, FColor.Gray) { m_messages = _messages; m_act = _message.Act; m_maxDistance = _message.GetFirstParameter<int>(); var points = new List<Point>(); for (var x = -m_maxDistance; x < m_maxDistance; ++x) { for (var y = -m_maxDistance; y < m_maxDistance; ++y) { var point = new Point(x, y); if (point.Lenght > m_maxDistance) continue; var liveCell = World.TheWorld.Avatar[point]; if (liveCell.Creature != null && !liveCell.Creature.IsAvatar) { points.Add(point); } } } m_targets.AddRange(points.Where(_point => _point.Lenght < m_maxDistance).OrderBy(_point => _point.Lenght)); Rebuild(); }
public override void Resize(Rct _newRct) { base.Resize(_newRct); m_messages.Resize(new Rct(Rct.Left, 0, Rct.Width, MESSAGES_HEIGHT)); m_map.Resize(new Rct(ContentRct.Left, m_messages.Rct.Height, Rct.Width, Rct.Height - m_messages.Rct.Height - STAT_HEIGHT)); m_stats.Resize(new Rct(0, Rct.Bottom - STAT_HEIGHT + 1, Rct.Width, STAT_HEIGHT)); }
public Room(Rct _roomRect, Rct _areaRect, Point _blockId) { RoomRectangle = _roomRect; AreaRectangle = _areaRect; BlockId = _blockId; ConnectedTo = new List<Room>(); }
public SelectDestinationUiBlock(TurnMessageUiBlock _messages, Rct _mapRct, Act _act) : base(_mapRct, null, FColor.Gray) { m_messages = _messages; m_act = _act; Rebuild(); }
protected UIBlock(Rct _rct, Frame _frame, FColor _color) { BlockFrame = _frame; ForeColor = _color; Rct = _rct; BackgroundColor = new FColor(1, 0, 0, 0); UpdateContentRct(); }
public ConfirmQuitBlock() : base(new Rct(2, 2, 15, 5), Frame.Frame1, FColor.Black) { ContentRct = new Rct(ContentRct.Left + 1, ContentRct.Top, ContentRct.Width - 1*2, ContentRct.Height); }
public static IEnumerable<Room> GenerateRooms(Random _random, Rct _rct, ICollection<Point> _objects, Point _blockId) { var ableVert = _rct.Width - MIN_ROOM_SIZE*2; var ableHor = _rct.Height - MIN_ROOM_SIZE*2; if ((ableHor > 1 || ableVert > 1) && (_rct.Width*_rct.Height < MIN_ROOM_SQUARE || _rct.Width > MAX_DIV_SIZE || _rct.Height > MAX_DIV_SIZE || _random.Next(_rct.Width + _rct.Height) > MIN_ROOM_SIZE)) { var divVert = 0; var divHor = 0; while (divVert == divHor) { divVert = ableVert > 0 ? _random.Next(ableVert + 1) : 0; divHor = ableHor > 0 ? _random.Next(ableHor + 1) : 0; } var rects = new List<Rct>(); if (divVert > divHor) { int vert; do { vert = MIN_ROOM_SIZE + _random.Next(ableVert); var val = vert; if (_objects.All(_point => _point.X != (_rct.Left + val))) break; } while (true); rects.Add(new Rct(_rct.Left, _rct.Top, vert, _rct.Height)); rects.Add(new Rct(_rct.Left + vert + 1, _rct.Top, _rct.Width - (vert + 1), _rct.Height)); } else { int hor; do { hor = MIN_ROOM_SIZE + _random.Next(ableHor); var val = hor; if (_objects.All(_point => _point.Y != (_rct.Top + val))) break; } while (true); rects.Add(new Rct(_rct.Left, _rct.Top, _rct.Width, hor)); rects.Add(new Rct(_rct.Left, _rct.Top + hor + 1, _rct.Width, _rct.Height - (hor + 1))); } foreach (var rct in rects) { if (rct.Width > _rct.Width || rct.Height > _rct.Height) { throw new ApplicationException("Доля больше чем место под нее"); } foreach (var room in GenerateRooms(_random, rct, _objects, _blockId)) { yield return room; } } yield break; } yield return MakeRoom(_rct, _random, _objects, _blockId); }
public virtual void AddedToBlock(BaseMapBlock _mapBlock) { BlockId = _mapBlock.BlockId; WorldRoomRectangle = new Rct ( RoomRectangle.Left + BlockId.X*Constants.MAP_BLOCK_SIZE, RoomRectangle.Top + BlockId.Y*Constants.MAP_BLOCK_SIZE, RoomRectangle.Width, RoomRectangle.Height); RandomSeed = _mapBlock.RandomSeed + RoomRectangle.LeftTop.GetHashCode(); }
protected ItemsSelectorUiBlock(Rct _rct, ESelectItemDialogBehavior _behavior, Act _act, IEnumerable<EssenceDescriptor> _descriptors) : base(_rct, Frame.Frame2, FColor.Green) { m_behavior = _behavior; m_act = _act; m_currentFilter = '*'; m_descriptors = _descriptors; }
public static void Fill(this BaseMapBlock _block, Random _rnd, WorldLayer _layer, IEnumerable<ETerrains> _defaultTerrains, Rct _rct) { var def = _defaultTerrains.ToArray(); for (var i = 0; i < _rct.Width; ++i) { for (var j = 0; j < _rct.Height; ++j) { _block.Map[i + _rct.Left, j + _rct.Top] = def.RandomItem(_rnd); } } }
public SelectToTakeOnUiBlock(Rct _rct, EquipmentUiBlock _equipmentUiBlock, EquipmentPresenter _equipmentPresenter) : base( _rct, ESelectItemDialogBehavior.SELECT_ONE, null, _equipmentUiBlock.Intelligent.GetBackPackItems()) { m_equipmentPresenter = _equipmentPresenter; m_equipmentUiBlock = _equipmentUiBlock; }
public void DrawRect(Rct _rct, FColor _toFColor) { GL.BindTexture(TextureTarget.Texture2D, 0); GL.Color4(_toFColor.R, _toFColor.G, _toFColor.B, _toFColor.A); GL.Begin(BeginMode.Quads); GL.Vertex2(_rct.Left, _rct.Top); GL.Vertex2(_rct.Right + 1, _rct.Top); GL.Vertex2(_rct.Right + 1, _rct.Bottom + 1); GL.Vertex2(_rct.Left, _rct.Bottom + 1); GL.End(); }
public void WindowClientSizeChanged(int _newWidthInCells, int _newHeightInCells) { var newRct = new Rct(0, 0, _newWidthInCells, _newHeightInCells); if (UiBlocks.Any(_block => _block.Rct != newRct)) { foreach (var uiBlock in UiBlocks) { uiBlock.Resize(newRct); } } if (World.TheWorld != null) { World.TheWorld.GameUpdated(); } }
public TurnMessageUiBlock(Rct _rct) : base(_rct, null, FColor.White) { MessageManager.NewMessage += MessageManagerNewMessage; MessageManager.NewWorldMessage += MessageManagerNewWorldMessage; }
public void ClearTiles(Rct _rct, FColor _backgroundColor) { if(m_gameProvider.TileMapRenderer==null) return; m_gameProvider.TileMapRenderer.Clear(_rct, _backgroundColor); }
public HelpKeyBindingUiBlock(Rct _rct) : base(_rct, Frame.Frame1, FColor.DarkGray) { }
public override void Resize(Rct _newRct) { base.Resize(_newRct); Rebuild(); }
public Bitmap this[ETextureSet _texture, int _x, int _y, FColor _fColor, bool _removeTransparency, bool _grayScale, bool _isTerrain, bool _plusHalfX, bool _plusHalfY] { get { Dictionary<Tuple<int, int, FColor, bool, bool, bool, bool>, Bitmap> dictionary; if (!m_tiles.TryGetValue(_texture, out dictionary)) { dictionary = new Dictionary<Tuple<int, int, FColor, bool, bool, bool, bool>, Bitmap>(); m_tiles[_texture] = dictionary; } Bitmap bitmap; var key = new Tuple<int, int, FColor, bool, bool, bool, bool>(_x, _y, _fColor, _removeTransparency, _grayScale, _plusHalfX, _plusHalfY); if (!dictionary.TryGetValue(key, out bitmap)) { var txtr = this[_texture, _isTerrain]; bitmap = new Bitmap(Constants.TILE_SIZE, Constants.TILE_SIZE); using(var gr = Graphics.FromImage(bitmap)) { gr.DrawImage(txtr, 0, 0, new Rectangle( Constants.TILE_SIZE * _x + (_plusHalfX ? (Constants.TILE_SIZE / 2) : 0), Constants.TILE_SIZE * _y + (_plusHalfY ? (Constants.TILE_SIZE / 2) : 0), Constants.TILE_SIZE, Constants.TILE_SIZE), GraphicsUnit.Pixel); } var transparent = txtr.GetPixel(0, 0); var rct = new Rct(0, 0, Constants.TILE_SIZE, Constants.TILE_SIZE); foreach (var point in rct.AllPoints) { var pixel = bitmap.GetPixel(point.X, point.Y); if (pixel == transparent) continue; var fcolor = new FColor(pixel.A, pixel.R, pixel.G, pixel.B).Multiply(1f / 255f); if(_grayScale) { fcolor = fcolor.ToGrayScale(); } var result = fcolor.Multiply(_fColor).GetColor();//.Multiply(255); if (_removeTransparency) { result.A = 255; } bitmap.SetPixel(point.X, point.Y, Color.FromArgb(result.A, result.R, result.G, result.B)); } dictionary.Add(key, bitmap); } return bitmap; } }
public MapUiBlock(Rct _rct) : base(_rct, null, FColor.Black) { World.TheWorld.LiveMap.SetViewPortSize(new Point(ContentRct.Width, ContentRct.Height)); MessageManager.NewWorldMessage += MessageManagerNewWorldMessage; }
public void Clear() { var rct = new Rct(WorldCoords, Constants.MAP_BLOCK_SIZE, Constants.MAP_BLOCK_SIZE); var arr = World.TheWorld.CreatureManager.InfoByCreature.Values.Where(_info => rct.Contains(_info.WorldCoords)).ToArray(); foreach (var info in arr) { World.TheWorld.CreatureManager.ExcludeCreature(info.Creature); } if (MapBlock == null) return; MapBlock = null; }
public EquipmentUiBlock(Rct _rct) : base(_rct, Frame.Frame1, FColor.White) { m_intelligent = World.TheWorld.Avatar; Rebuild(); }
public virtual void Resize(Rct _newRct) { Rct = _newRct; UpdateContentRct(); }
public StartSelectorUiBlock(Rct _rct, TheGame _game) : base(_rct, Frame.Frame1, FColor.DarkGray) { m_game = _game; }
public AskDirectionUiBlock(Rct _rct, AskMessage _message) : base(new Rct(_rct.Left, _rct.Top, _rct.Width, 1), null, FColor.Gray) { m_message = _message; }
public void Clear(Rct _rct, FColor _backgroundColor) { GL.BindTexture(TextureTarget.Texture2D, 0); GL.Begin(BeginMode.Quads); var xy = new Point(_rct.Left, _rct.Top) * Constants.TILE_SIZE; var xy1 = new Point(_rct.Right + 1, _rct.Bottom + 1) * Constants.TILE_SIZE; GL.Color4(_backgroundColor.R, _backgroundColor.G, _backgroundColor.B, _backgroundColor.A); GL.Vertex2(xy.X, xy.Y); GL.Vertex2(xy1.X, xy.Y); GL.Vertex2(xy1.X, xy1.Y); GL.Vertex2(xy.X, xy1.Y); GL.End(); for (var i = _rct.Left; i <= _rct.Right; i++) { for (var j = _rct.Top; j <= _rct.Bottom; j++) { m_tiles[i, j].Clear(); } } }
public AskHowMuchUiBlock(Rct _rct, AskMessage _message) : base(new Rct(_rct.Left, _rct.Top, _rct.Width, 1), null, FColor.Gray) { m_message = _message; m_count = _message.GetFirstParameter<int>().ToString(); }